[英]lambda function is not being updated with cloudformation and pipeline in AWS
I'm trying to build a pipeline to automate a lambda function deployment on AWS.我正在尝试构建一个管道来自动化 AWS 上的 lambda function 部署。 I created a pipeline, a codebuild and needed IAM roles and integrated them with cloudformation.我创建了一个管道、一个代码构建和所需的 IAM 角色,并将它们与 cloudformation 集成。
here's my buildspec.yml:这是我的 buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 14
commands:
- echo "Installing from package.json"
# - npm install
pre_build:
commands:
- echo "Build on `date`"
# - npm run test
post_build:
commands:
- zip -r lambda.zip index.js template.yml
- aws s3api put-object --bucket github-lambda-demo --key lambda.zip --body lambda.zip
artifacts:
files:
- template.yml
discard-paths: yes
And this is my cloudformation template:这是我的 cloudformation 模板:
AWSTemplateFormatVersion: '2010-09-09'
Description: Template for Lambda Sample.
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: lambda-role
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: github-lambda-demo
S3Key: lambda.zip
Description: demo for lambda deployment
FunctionName: github-lambda-demo
Handler: index.handler
PackageType: Zip
# Layers:
# - String
MemorySize: 256
Role:
Fn::GetAtt:
- LambdaRole
- Arn
Runtime: nodejs14.x
Timeout: 300
All the steps are done quite right with no errors in codePipeline but my lambda function source is not being update as it should be.所有步骤都完成得非常正确,codePipeline 中没有错误,但我的 lambda function 源没有按照应有的方式更新。
Any help?!有什么帮助吗?!
This is expected behavior for Lambda Resource in cloudformation, Straight from docs :这是 cloudformation 中Lambda 资源的预期行为,直接来自文档:
Changes to a deployment package in Amazon S3 are not detected automatically during stack updates.在堆栈更新期间不会自动检测到对 Amazon S3 中的部署 package 的更改。 To update the function code, change the object key or version in the template.要更新 function 代码,请更改模板中的 object 密钥或版本。
So, typically two options:因此,通常有两种选择:
First option using versioned S3 Bucket :使用版本化 S3 Bucket 的第一个选项:
Second option using ssm parameter使用 ssm 参数的第二个选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.