aws serverless - 导出 cognito 授权方的输出值

aws serverless - exporting output value for cognito authorizer

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

正在尝试从 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}

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

export AWS_PROFILE=your_profile

必须在您正在做的sls deploy终端window上完成,而不是在另一个终端window上完成。这是一个愚蠢的错误,但我不希望其他人在这方面浪费时间