The docs say I should specify a application revision in either.yaml or.json format when calling codedeploy. But how do I deploy the actual function code through code deploy?
There is no option to provide a zip with the code inside it. Only json and yaml files are accepted. How do I actually update/add the lambda function code through codedeploy? The below images shows even through aws console, I can only specify a yaml or json appspec file.
How do I actually deploy my function code here? ![Text]()
You have to deploy it before your CodeDeploy (CD) stage. You can use CodeBuild (CB) for that. So in your CI/CD pipeline, your CD stage would be executed after CB stage. The CB stage would deploy and create a version of your function, which then would be used as an input to CD.
As @Marcin mentioned, you need to update the actual function through your codebuild specification yaml file.
there are plenty of approaches for having CI/CD for serverless lambda functions. (Cloudformation, Terraform, CodeDeploy, using only CodeBuild and update the code there!)
what I personally do is using ECR, Docker Images to handle the CI/CD proccess, here's the flow:
in your buildspec.yml
file:
here's a sample:
version: 0.2
phases:
pre_build:
commands:
- echo "Build on `date`"
- aws ecr get-login-password --region ca-central-1 | docker login --username AWS --password-stdin YOUR_ECR_ADDRESS
- npm run test
build:
commands:
- echo Building the Docker image ... | tee -a log.txt
- docker build -t YOUR_ECR_ADDRESS/your-lambda:latest . 2>&1 | tee -a log.txt
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push YOUR_ECR_ADDRESS/your-lambda:latest
- aws lambda update-function-code --function-name your-lambda --image-uri YOUR_ECR_ADDRESS/your-lambda:latest > /dev/null
You can also have cloudformation as last stage so you can change a function specifications ie roles, timeout, ram usage, etc by changing only a template yml file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.