I’m currently working on setting up a CI/CD pipeline in AWS CodePipeline to deploy a Lambda function as a Docker image. My pipeline consists of three stages: Source, Build, and Deploy.
What’s Working:
Source Stage: I’m using Bitbucket as my source. Every time I push code to the repository, the pipeline is triggered as expected.
Build Stage: The build stage uses CodeBuild to build a Docker image from my code, pushes it to Amazon ECR, and then successfully updates my Lambda function with the latest image using the aws lambda update-function-code command. This works perfectly, and my Lambda function gets updated with the new image without any issues.
The Problem:
Deploy Stage: I wanted to make my pipeline more professional by separating the deployment process into a distinct deploy stage. However, when I added the deploy stage to handle the Lambda function update, I encountered the following issues: The deploy stage takes a long time and eventually fails with the error: “The AWS Lambda function ci-cd-test failed to return a result. Check the function to verify that it has permission to call the PutJobSuccessResult action and that it made a call to PutJobSuccessResult.” It seems that the deploy stage might be invoking the Lambda function after deployment, and because my Lambda function isn’t designed to handle CodePipeline job events, it causes a timeout.
My Questions:
-
Why is the deploy stage invoking the Lambda function after updating it? Shouldn’t it only update the function with the new image and not invoke it?
-
Is there a best practice for deploying Lambda functions as Docker images using a dedicated deploy stage in CodePipeline?
-
Should I stick with updating the Lambda function in the build stage, or is there a more “professional” way to handle this with a separate deploy stage?
Here’s my current buildspec file and Lambda function for reference:
Buildspec file
Lambda Function
Any insights or suggestions would be greatly appreciated!
Thank you!
These are the 2 links which somewhat describe my problem:
Link 1
Link 2