Automate the Experience of Lambda Versioning with Configuration Change and Code Change Using CloudFormation and Code Pipeline
Tags: awscodepipeline, cloudformation, lambda, adoptk8swithdevtron
Published: 2022-05-28 19:04:19

“ I have checked the documents of AWS to automate the experience of lambda versioning with change in configuration and code. I have checked for AWS code pipeline service which makes the process easy and automates for everyone. The Pricing of Code pipeline is based on when the pipeline runs. Also price for code build. ”

A keyword define "**Devtron**" play an important role in sorting the complexity of DevOps, AppOps and Kubernetes. Also "**GitHub**" helps to integrate and automate. Both Devtron and GitHub is an open source one.

In this post, you will experience the automation of lambda versioning with configuration and code change using cloudformation and code pipeline. Here I have created a code pipeline to automate lambda creation and its versioning with change in set parameters using cloud formation with artifacts to be stored in s3 bucket.

#Prerequisites
You’ll need a [Github](https://github.com/) account and git installed on a local machine. You’ll need [AWS CLI](https://aws.amazon.com/cli/) installed and configured on your local machine.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2754bksayui2ysc6iwnj.png)
The architecture diagram shows the overall deployment architecture with data flow, code build, code deploy, code pipeline, s3, sns, cloud formation, lambda.

#Solution overview
The blog post consists of the following phases:
1. Create of IAM Role, S3 Bucket, Buildspec.yml, Template.yaml and Sample HelloWorld.js File
2. Create of CodePipeline and Build Project
3. Create SNS Topic with Subscription and Check of CloudFormation with Lambda Creation
4. Testing of Lambda Configuration Parameters and Code Deploy while Updating in GitHub

##Phase 1: Create of IAM Role, S3 Bucket, Buildspec.yml, Template.yaml and Sample HelloWorld.js File 
1. Open the IAM Console and create a role for cloudformation with AWS lambda execute policy and inline policy with required permission. Create an S3 bucket named as lambda-ci-cd-demo-test. Also configure buildspec.yml file, template.yaml file and helloworld.js file as per the requirement to build a lambda code and configuration part.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j4mbbolm02i6ctkir52m.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p93h7olg6mb7ivbffqkg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1e52lflrikc0vp5ys7le.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzrv4wayn97k6h4jya62.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6p1enf0xlpafyutwymk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sav590vuodaq1an7xwmo.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6opr5w1e2r09uwicww5j.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rncu9w477ybvd1g2q6yr.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sslayf4gwgtphy1y5yml.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l0czvp82w3drx3b46d2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jai980iq3nwboi9ncb69.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cl6ws800a26rrifw7hd5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwqetbn1pw25g4sxkzaw.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnit368hux2f62w9w9oj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3j8bftonk0lqjxzrdu5p.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqihxme4cn9cf1pjeudv.png)

##Phase 2: Create of CodePipeline and Build Project  
1. Open codepipeline console and create a pipeline with source as github and provider as cloudformation with default IAM role and custom s3 inline policy to be attached with the role. Also build a project with custom settings. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2oguyvmayh40t7yu8fu.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iqx16f9lxawc7f1p2ik.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6y4rvrc43ve8g2u33pq.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b6orkrvxzf95xq4odo4c.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbqtlvejhkghhm2q5yzm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hav6zf9ec6p4sd7bikjp.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/etnp3099hki2mby0x2dz.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zq4z17b4nxq4k8l1nmz.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7grb2yle7pi9976std4s.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow9tztvulht3e99s1myj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5resbmz8w0mayc5netcx.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2uxpx6eo9glr9iateio.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qb7kb60gpq7qimrwunm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwnoh4gmwrcjz3hwz34v.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1b5ccjndg4rma4hlm7b.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ao47ndj41n59eptm1amq.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7265aao74w7frfz3nvg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wteqphj9u6s19u01ympz.png)

##Phase 3: Create SNS Topic with Subscription and Check of CloudFormation with Lambda Creation  
1. Open the Amazon Simple Notification Service and create a topic with subscription for approval notification in the code pipeline. In the code pipeline the stages as source, build, deploy as createchangeset, approvechangeset, executechangeset. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62qb2q0okrkaswb69wcx.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsb3i2y1mxsx8enw0rk7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3r37a44pi73qx3qw919.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mg1tw3ridzvqc7xiq5d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4qxu843cgxz9e7kq7d9.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/df5i1ba5erd516uo0zwm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v2gozpbx17s7fww36mie.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j24brs0emb83jyxkvkrh.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp329u7z4q4kijyns8sb.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tiji9kq819bgt3iyc79y.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/587xbv6ww54m5i9f0ea9.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wvlijdd1trcfkwc9wd0i.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rakm7s8xllz0nvngy4ca.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tt7zneeskgf1ycalw0bd.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ky0m7ns2mreuicaqq1w.png)

##Phase 4: Testing of Lambda Configuration Parameters and Code Deploy while Updating in GitHub
1. Test the lambda configuration and code in doing changes on various parameters in github.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aw9579x440hym8vk8fri.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh5n7g6cjzhv9ynrwl5b.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a628s97y8dc4tnhmbs1i.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9pma73nrbto10gk6mvk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vszihi0omnmv2lng98nx.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6m99mudlqedrxdestlw.png)

#Clean-up
Delete Code Pipeline, Code Build, IAM Role, S3 Bucket, Cloud Formation, SNS.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of Code Build = $0.0

Cost of Lambda = $0.0

Cost of Simple Notification Service = $0.0

Cost of Simple Storage Service = $1.0

Total Cost = $(0.0 + 0.0 + 0.0 + 1.0) = $1.0

#Summary
In this post, I showed “how to automate the experience of lambda versioning with configuration change and code change using cloudformation and code pipeline”.

For more details on AWS CodeDeploy, Checkout Get started AWS CodeDeploy, open the [AWS CodeDeploy console](https://ap-south-1.console.aws.amazon.com/codesuite/codedeploy/deployments?region=ap-south-1&deployments-meta=eyJmIjp7InRleHQiOiIifSwicyI6e30sIm4iOjUwLCJpIjowfQ). To learn more, read the [AWS CodeDeploy documentation](https://docs.aws.amazon.com/codedeploy/?id=docs_gateway). For more details on AWS CodePipeline, Checkout Get started AWS CodePipeline, open the [AWS CodePipeline console](https://ap-south-1.console.aws.amazon.com/codesuite/codepipeline/pipelines?region=ap-south-1&pipelines-meta=eyJmIjp7InRleHQiOiIifSwicyI6eyJwcm9wZXJ0eSI6InVwZGF0ZWQiLCJkaXJlY3Rpb24iOi0xfSwibiI6MTAsImkiOjB9). To learn more, read the [AWS CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/?id=docs_gateway). 

For more details on AWS CodeBuild, Checkout Get started AWS CodeBuild, open the [AWS CodeBuild console](https://us-east-1.console.aws.amazon.com/codesuite/codebuild/start?region=us-east-1). To learn more, read the [AWS CodeBuild documentation](https://docs.aws.amazon.com/codebuild/?id=docs_gateway). For more details on AWS CloudFormation, Checkout Get started AWS CloudFormation, open the [AWS CloudFormation console](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/). To learn more, read the [AWS CloudFormation documentation](https://docs.aws.amazon.com/cloudformation/?id=docs_gateway).

For more details on **Devtron and GitHub**, Checkout Links:
[Devtron Website](https://devtron.ai/)
[GitHub Repo](https://github.com/devtron-labs/devtron)
[Join the Discord Community](https://discord.com/invite/jsRG5qx2gp)
[Follow on Twitter](https://twitter.com/DevtronL)
[Raise feature requests, suggest enhancements, report bugs](https://github.com/devtron-labs/devtron/issues)
[Read Devtron Blog](https://devtron.ai/blog/)

Lets quickly adopt and try it! And post the response using **#AdoptK8sWithDevtron** **#devtron**

The above blog is submitted as part of 'Devtron Blogathon 2022' - [https://devtron.ai/](https://devtron.ai/)
Check out Devtron's GitHub repo - [https://github.com/devtron-labs/devtron/](https://github.com/devtron-labs/devtron/) and give a ⭐ to show your love & support.
Follow Devtron on LinkedIn - [https://www.linkedin.com/company/devtron-labs/](https://www.linkedin.com/company/devtron-labs/) and Twitter - [https://twitter.com/DevtronL/](https://twitter.com/DevtronL/), to keep yourself updated on this Open Source project.

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)