我想将 cognito 授权方添加到我的 lambda 函数中,但为此我需要 arn cognito,它是在堆栈 coud 形成中创建的(我的资源部分中的 CognitoUserPool(。我正在使用无服务器框架。
无服务器.yml 文件的一部分
graphql:
handler: src/lambda-functions/graphql/index.handler
timeout: 30
memorySize: 2048
events:
- http:
path: graphql
method: any
private: true
cors: true
authorizer:
arn:
Fn::Join:
- ''
- - 'arn:aws:cognito-idp:'
- ${self:provider.region}
- ':'
- Ref: AWS::AccountId
- ':userpool/'
- Ref: CognitoUserPool
我在部署应用程序时收到错误:
TypeError: functionArn.split is not a function
在调试时,我发现Fn::join的输出应该传递给的函数是 object:
{"Fn::Join":["",["arn:aws:cognito-idp:","eu-west-1",":",{"Ref":"AWS::AccountId"},":userpool/",{"Ref":"CognitoUserPool"}]]}
并且应该传递给函数已经解析 arn,例如:
arn:aws:cognito-idp:eu-west-1:XXXXXXXXXX:userpool/eu-west-XXXXXXX
如何强制计算来自Fn::join的输出并将该值传递给arn属性?
据此,为授权方指定名称可让您使用内部函数来引用 ARN:
graphql:
handler: src/lambda-functions/graphql/index.handler
timeout: 30
memorySize: 2048
events:
- http:
path: graphql
method: any
private: true
cors: true
authorizer:
name: CognitoAuthorizer #supply a unique name here
arn:
!GetAtt CognitoUserPool.Arn