【问题标题】:aws serverless - exporting output value for cognito authorizeraws serverless - 为 cognito 授权方导出输出值
【发布时间】:2020-05-05 21:17:47
【问题描述】:

我正在尝试在我的堆栈之间共享 cognito 授权方,我正在导出我的授权方,但是当我尝试在另一个服务中引用它时出现错误

尝试从 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

【问题讨论】:

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


    【解决方案1】:

    回答我自己的问题

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

    替换了这个 -

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

    与 -

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

    【讨论】:

      【解决方案2】:

      如果您遇到 试图从 CloudFormation 请求未导出的变量。堆栈名称:“myApp-services-test” 请求的变量:“ExtApiGatewayAuthorizer-test”。,在导出配置文件时,即

      export AWS_PROFILE=your_profile
      

      必须在您正在执行sls deploy 的终端窗口上完成,而不是在另一个终端窗口上完成。这是一个愚蠢的错误,但我不希望其他人为此浪费时间

      【讨论】:

        猜你喜欢
        • 2021-07-28
        • 2019-12-12
        • 2021-09-25
        • 1970-01-01
        • 2021-08-05
        • 2019-02-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-18
        相关资源
        最近更新 更多