【发布时间】:2020-09-27 10:03:21
【问题描述】:
我正在尝试使用 AWS SAM 框架来创建一个 lambda,以用作 CloudFront 事件处理程序。 AWS::Serverless::Function 似乎不支持 Version 属性。我看到的错误:
com.amazonaws.services.cloudfront.model.InvalidLambdaFunctionAssociationException: The function ARN must reference a specific function version. (The ARN must end with the version number.)
我找到了this answer,这让我尝试了它。我的 CloudFormation YAML 文件的相关部分:
Resources:
CloudFrontFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: cloudfront-handler/hello_world/
Handler: app.lambda_handler
Runtime: python3.7
Outputs:
CloudFrontFunctionArn:
Description: CloudFront Function ARN with Version
Value: !Join [':', [!GetAtt CloudFrontFunction.Arn, !GetAtt CloudFrontFunction.Version]]
当我sam deploy 时出现以下错误。
Waiting for changeset to be created..
Error: Failed to create changeset for the stack: my-sam-app, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Template error: resource CloudFrontFunction does not support attribute type Version in Fn::GetAtt
AWS::Lambda::Function 上可用的属性是 documented here,它列出了 Version 作为属性之一。所以看来AWS::Serverless::Function 不支持获取版本。如何解决这个问题,以便部署使用 AWS SAM 框架实现的 CloudFront 事件处理程序?
更新
根据@mokugo-devops(谢谢!),解决这个问题的方法是像这样添加AutoPublishAlias: live:
Resources:
CloudFrontFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: cloudfront-handler/hello_world/
Handler: app.lambda_handler
Runtime: python3.7
AutoPublishAlias: live
Outputs:
CloudFrontFunctionVersion:
Description: CloudFront Function ARN with Version
Value: !Ref CloudFrontFunction.Version
【问题讨论】:
-
您是否按照您提供的链接定义了资源
AWS::Lambda::Version?AWS::Lambda::Version是独立于AWS::Serverless::Function的资源。
标签: amazon-web-services amazon-cloudformation amazon-cloudfront aws-sam