aws-lambda - aws serverless - 导出 Cognito 授权者的输出值

标签 aws-lambda aws-cloudformation aws-api-gateway amazon-cognito serverless-framework

我试图在我的堆栈之间共享认知授权者,为此我正在导出我的授权者,但是当我尝试在另一个服务中引用它时,我收到错误

尝试从 CloudFormation 请求非导出变量。堆栈名称:“myApp-services-test” 请求的变量:“ExtApiGatewayAuthorizer-test”。

这是我定义并导出授权者的堆栈:

    CognitoUserPool:
  Type: AWS::Cognito::UserPool
  Properties:
    # Generate a name based on the stage
    UserPoolName: ${self:provider.stage}-user-pool
    # Set email as an alias
    UsernameAttributes:
      - email
    AutoVerifiedAttributes:
      - email

    ApiGatewayAuthorizer: 
  Type: AWS::ApiGateway::Authorizer
  Properties: 
    Name: CognitoAuthorizer
    Type: COGNITO_USER_POOLS
    IdentitySource: method.request.header.Authorization
    RestApiId: { "Ref": "ProxyApi" }
    ProviderARNs: 
      - Fn::GetAtt:
          - CognitoUserPool
          - Arn

    ApiGatewayAuthorizerId:
  Value:
    Ref: ApiGatewayAuthorizer
  Export:
    Name: ExtApiGatewayAuthorizer-${self:provider.stage}

这已成功导出,因为我可以在 AWS 控制台的堆栈导出列表中看到它。

我尝试在另一个堆栈中引用它,如下所示:

  myFunction:
handler: handler.myFunction
events:
  - http:
      path: /{userID}
      method: put
      cors: true
      authorizer:
        type: COGNITO_USER_POOLS
        authorizerId: ${myApp-services-${self:provider.stage}.ExtApiGatewayAuthorizer-${self:provider.stage}}

我的环境信息

  Your Environment Information ---------------------------
 Operating System:          darwin
 Node Version:              12.13.1
 Framework Version:         1.60.5
 Plugin Version:            3.2.7
 SDK Version:               2.2.1
 Components Core Version:   1.1.2
 Components CLI Version:    1.4.0

最佳答案

回答我自己的问题

看起来我应该通过输出名称导入而不是输出导出名称,这有点奇怪,我见过的所有文档都指向导出名称,但这就是我能够使其工作的方式

替换了这个 -

authorizerId:${myAppservices-${self:provider.stage}.ExtApiGatewayAuthorizer-${self:provider.stage}}

与-

authorizerId:${myApp-services-${self:provider.stage}.ApiGatewayAuthorizerId}

关于aws-lambda - aws serverless - 导出 Cognito 授权者的输出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59813541/

相关文章:

amazon-web-services - 是否可以将公共(public) IP 分配给 AWS 中的 Lambda 函数?

kotlin - AWS Lambda的意外行为

amazon-web-services - cfn-init 检测什么类型的更改?

java - 从现有 AWS Glue 爬网程序获取 Cloudformation

amazon-web-services - 使用 ApiGateway Authorizer 验证 Github Payload 签名(X-Hub-Signature)

java - AWS lambda : How to get query params from Api Gateway in lambda function implemented in Java

node.js - 在 Lambda 函数中使用 axios 时根据先前的请求设置 cookie

json - aws lambda node js返回对象实例的转义JSON

amazon-web-services - AWS CloudFormer 堆栈创建失败,并显示(未能在指定持续时间内接收 1 个资源信号)

ruby-on-rails - 是否可以将自签名证书与需要来自 API 网关的客户端证书的 EC2 实例一起使用