当使用AWS SAM部署时,有时会遇到无法正确更新Lambda层版本的问题。以下是一种解决方法,包含代码示例:
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: MyFunction
Handler: index.handler
Runtime: nodejs14.x
Layers:
- !Ref MyLayer
MyLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: MyLayer
ContentUri: ./layer-code
CompatibleRuntimes:
- nodejs14.x
aws cloudformation package --template-file sam-template.yaml --output-template-file packaged-template.yaml --s3-bucket
aws cloudformation deploy --template-file packaged-template.yaml --stack-name my-stack --capabilities CAPABILITY_IAM
aws lambda delete-layer-version --layer-name MyLayer --version-number
通过按照以上步骤操作,您应该能够解决AWS SAM部署未能正确更新层版本的问题。