August 16, 2023

Creating an Automated Deployment Pipeline - CodeCommit to Lambda

The best time to establish protocols with your clients is when you onboard them.


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

“Merge conflict” is one of the worst messages a developer can see in Git.

You’ve worked on a feature for hours and finally have your code perfect.

However, someone else has changed the same section of the file, so you must now compare the differences, decide which edits to keep, and run all of your tests again before attempting to merge for the second time. Consider working on a highly integrated team that is attempting to release new features at a rapid pace.

The CI/CD approach was developed to address this issue and streamline development. CI/CD is a strategy for automating the development process in order to reduce turnaround time.

Continuous integration, also known as CI, is the practise of frequently merging code changes into a shared branch.

Continuous delivery or deployment, which both automate the release and rollout of the application after merging, can be referred to as CD.

Objective :

To automatically deploy the lambda function when new changes are pushed into the master branch.

Step 1 : Include buildspec.yml file in the root directory of your project.

Check here for the documentation of buildspec references :

Step 2 : Set up the Code Pipeline

The required IAM permissions for the IAM user :

  • AWSCodeDeployFullAccess
  • AWSCodeBuildAdminAccess
  • AWSCodePipeline_FullAccess

  1. Search CodePipeline in services search bar

2. Select Create Pipeline

3. Choose the pipeline settings

4. Select AWS CodeCommit in the Source provider. Select a Repository name and the Branch name (usually master) in the repository that you want to configure auto deploy for lambda function

5. Select AWS CodeCommit in the Build provider and a region and select Create Project if you want to create a new project build or select an existing project build.

6. Creating a new Project build — Give a Project name for the build and restrict the number of concurrent builds for this project.

7. Configure Build Environment. Select Managed image in Environment image and Amazon Linux 2 as Operating System. Select Standard Runtime and the latest image version.

8. Select New service role and a default name will be filled in Role name. Add additional configurations like environment variables, compute type, if necessary.

The build environment requires a buildspec.yml file. If the name is different, please specify the entire path of the build spec file.

9. Specify the log configuration and select Continue to CodePipeline

10. In the deploy stage, select Skip deploy stage as we have specified the deployment in buildspec.yml file in the build stage itself.

11. Review the pipeline and select Create pipeline

Step 3 : Troubleshooting the build error

The build fails as the service-role of the build created does not have the right IAM access for deploying the lambda function.

To overcome this, go to Build projects -> Build details->Environment->Service role,

Select the service role and attach Administrator Access permission to this role. (It is advised to provide only the necessary permissions required- Administrator Access provides the entire access to all the available AWS services). Select Add Permissions->Attach policies

Select AdministratorAccess and select Attach policies ( the required permissions can be added in a similar manner )

Step 4 : Remove the line “profile” in the serverless.yml file of our project as we have the profile configured in our local system (.aws/credentials) , but the deployment (build) is done within another environment ( Amazon Linux machine, in this case ) and that will not have our profile credentials being set up.

The deployment is done within the Linux environment with the IAM permissions previously set for the user.

So, whenever the master branch encounters a change to it, the code pipeline is triggered, which in turn triggers the code build and the lambda function is deployed automatically.

After any changes are pushed into master, we can open the Code Pipeline project and see the pipeline getting executed.

Success logs — after deployment ( build success ) :

August 16, 2023
min read
Subscribe to our newsletter
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Share this article:

More articles