gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:31:52 24 4
gpt4 key购买 nike

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com