DEV Community

hoan-pham-duy
hoan-pham-duy

Posted on

Bitbucket Pipeline build and deploy Lambda Container Image in AWS

Summary
In this post, I want to share how I build CI/CD system that Bibucket Pipeline can build and deploy Lambda Container Image in AWS.
The architecture of this post:

Image description

Steps:
Step 1: Create a repository at Elastic Container Registry
Image description
I set it as private repository, Linux Operating systems, Architecture x86
After create the ECR repository, we can see the image URI and the push command to know how we upload our container to ECR.
Image description
The push commands:
Image description

Step 2: Push a container from your local machine to ECR.
Currently, I use sample python lambda docker from https://github.com/lambci/docker-lambda.git
Image description

Step 3: Create Lambda Container Image that using the Image URI
Choose the container tab
Image description
Choose the repository and the container we've just pushed
Image description

Step 4: Create Bitbucket repository
Image description

Step 5: Add bitbucket-pipelines.yml file to the projects to run pipeline and push it to Bitbucket Pipeline
We need to fill some information from AWS to bitbucket-pipelines.yml like IMAGE_NAME, FUNCTION_NAME, the link in "docker login"
Image description

Step 6: Set up your AWS credentials in repository's variable
Image description

Step 7: Run the pipeline in Bitbucket and wait for the pipeline completes build Lambda container images, push to ECR and Update Lambda Image URI.
Image description
Image description
Step 8: Check the image we pushed in ECR from Bitbucket pipeline, check the Lambda's Image URI with the name convention: TAG=$BITBUCKET_BUILD_NUMBER-$BITBUCKET_BRANCH-$BITBUCKET_TAG
In my case, the BITBUCKET_BUILD_NUMBER = 2 and run in master branch with empty BITBUCKET_TAG
Image description
Image description

That's all of what I want to share in this post.
Please let me know if you have other questions!

Latest comments (0)