我正在尝试使用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事件处理程序?
默认情况下,该功能将自动部署版本。相反,您将需要指定AutoPublishAlias
属性。
更多可用信息here。