AWS CodePipeline Lambda Deployment: Build Stage Updates Lambda Function Successfully, But Issues When Adding Deploy Stage

0

Hi everyone,

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. These are the 2 links which somewhat describe my problem:

Link 1

Link 2

My Questions:

  1. 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?
  2. Is there a best practice for deploying Lambda functions as Docker images using a dedicated deploy stage in CodePipeline?
  3. 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:

Here is my build Spec file

Lambda Function:

Here is my lambda function

Here is what my ci/cd deploy stage looks like:

Enter image description here

Enter image description here

Any insights or suggestions would be greatly appreciated!

Thank you!

2 Answers
0

PutJobSuccessResult represents the success of a job as returned to the pipeline by a job worker. Used for custom actions only - so you must have configured a custom action calling your ci-cd-test Lambda. Custom actions can be included in your pipeline as a Build, Deploy, Test or Invoke action.

EXPERT
answered a month ago
  • Hi sinksman, Thank you for taking time to look into my problem. I'm a beginner in AWS. After reading your answer, I believe there is something wrong with my deployment stage. I updated my question and attached the deploy stage screen shots above. Could you please take a look and tell me what I'm doing wrong over there?

0

Hi @Subhan, it does indeed look like you've configured a custom action using your Lambda function as the provider. This is asking your Lambda function to execute custom deployment steps rather than deploying the function itself.

I'm only familiar with using CloudFormation/SAM to deploy Lambda in which case the CodePipeline deploy provider is CloudFormation. However I'm guessing that in your case you'd want to configure CodeDeploy as the provider, telling it to deploy your Lambda function. This page may help - https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-steps-lambda.html.

EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions