【发布时间】:2019-12-31 02:54:15
【问题描述】:
我似乎无法让 Ref 或 Fn:GetAtt 返回用于设置资源的有效值。
serverless.yml
...etc...
functions:
bearerTokenAuthentication:
handler: app.bearerTokenAuthentication
name: ${self:service}-auth-bearer
resources:
- ${file(./serverless_resources.yml)}
serverless_resources.yml
Resources:
ApiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
Name: restapi-${self:provider.stage}
Description: Endpoints
ApiKeySourceType: HEADER # (to read the API key from the X-API-Key header of a request)
ApiGatewayBearerAuthorizer:
Type: AWS::ApiGateway::Authorizer
Properties:
Type: token
IdentitySource: method.request.header.Authorization
Name: BearerAuthorization
AuthorizerResultTtlInSeconds: 300
AuthorizerUri: !Join #arn:aws:apigateway:${self:provider.region}:lambda:path/${self:functions.bearerTokenAuthentication.name}
- ''
- - 'arn:aws:apigateway:'
- !Ref 'AWS::Region'
- ':lambda:path/2015-03-31/functions/'
- !GetAtt
- bearerTokenAuthentication # also tried !Ref bearerTokenAuthentication and '${self:functions.bearerTokenAuthentication.name}'
- Arn
- /invocations
RestApiId: !Ref ApiGateway
无论我做什么,GetAtt 都找不到在bearerTokenAuthentication 中声明的 Lambda 函数的 ARN。我只是不断收到此错误:
错误:CloudFormation 模板无效:模板错误:Fn::GetAtt 实例引用未定义资源 BearerTokenAuthentication
...或者如果尝试Ref ...
错误:CloudFormation 模板无效:模板格式错误:模板的 Resources 块中未解决的资源依赖项 [bearerTokenAuthentication]
是否可以从资源部分引用 Lambda ARN?从错误消息看来,它正在寻找“资源”名称。我一直认为 lambda 函数声明也被认为是一种资源(当然除了明显的 Resources: 块之外),也许我误解了一些东西。
【问题讨论】:
-
如果是“未解决的资源依赖”问题,您可以在“ApiGatewayBearerAuthorizer”的 Type 和 Properties 属性之间添加“DependsOn: bearerTokenAuthentication”,这将阻止创建该资源,直到 bearerTokenAuthentication 创建并可用。
-
什么都不做。似乎完全忽略了它。
标签: amazon-web-services aws-lambda serverless-framework serverless