
Step-by-Step Procedure for Automating Lambda deployment using Jenkins
Amazon offers end-to-end solutions to continuous integration and continuous deployment. Jenkins can be installed on EC2 to automate deployments.
Jenkins is an open-source automation server. There are hundreds of plugins that can be used to build, deploy, and automate any project. We will discuss how Jenkins can be used as a simple CI server, and how to automate AWS Lambda deployment and invocation.
We are using a plugin to achieve the above use case.
Flow Diagram
Prerequisites:
Follow these steps to get it installed: Jenkins running on EC2
Step by Step Guide
Step 1: AWS Lambda plugin installation
Click Manage Jenkins or Manage Plugins to search and install the AWS Lambda plugin.
Step 2: IAM setup
For deployment and invocation, we need access to the GetFunction, CreateFunction, UpdateFunctionCode and UpdateFunctionConfiguration, InvokeFunction
We need access to iam:PassRole to attach a role to the Lambda.IAM policy “Version”: “2012-10-17”, “Statement”: [ “Sid”: “Stmt1432812345671”, “Effect”: “Allow”, “Action”: [ “lambda:GetFunction”, “lambda:CreateFunction”, “lambda:UpdateFunctionCode”, “lambda:UpdateFunctionConfiguration”,”lambda:InvokeFunction” ], “Resource”: [ “arn:aws:lambda:REGION:ACCOUNTID:function:FUNCTIONNAME” ] , “Sid”: “Stmt14328112345672”, “Effect”: “Allow”, “Action”: [ “iam:Passrole” ], “Resource”: [ “arn:aws:iam::ACCOUNTID:role/FUNCTIONROLE” ] ]123456789101112131415161718192021222324252627282930″Version”: “2012-10-17″,”Statement”: [“Sid”: “Stmt1432812345671″,”Effect”: “Allow”,”Action”: [“lambda:GetFunction”,”lambda:CreateFunction”,”lambda:UpdateFunctionCode”,”lambda:UpdateFunctionConfiguration”,”lambda:InvokeFunction”],”Resource”: [“arn:aws:lambda:REGION:ACCOUNTID:function:FUNCTIONNAME”],”Sid”: “Stmt14328112345672″,”Effect”: “Allow”,”Action”: [“iam:Passrole”],”Resource”: [“arn:aws:iam::ACCOUNTID:role/FUNCTIONROLE”]]
In the policy, replace ACCOUNTID with FUNCTIONROLE. Jenkins can attach this Instance profile role to the EC2 instance.
Step 3: Jenkins Job Configuration
Create a Maven project using Java source code repository details.
Test and build code according to your requirements
Add AWS Lamba deployment to your post-build steps
Configure the required details such as AWS Region, Function Name and Role, zip location (generated Jar which is built). We don’t need AWS keys as we use the Instance role.
If you configure lambda within VPC, you can also set environment variables and subnets. To leverage an instance role, please check Use Instance credentials
Done!!! Save and build a job to get your lambda started
Conclusion:
You can deploy continuous code into our lambda functions whenever there is a change in code.
Stay tuned for more information about DevOps and CICD. You can ask any questions about the CICD process in the comment section below. I will respond as soon as possible.
About CloudThat
CloudThat is a Microsoft Gold Partner, AWS Advanced Consulting Partner and a Google Cloud Partner. We have successfully managed many AWS-related projects for our clients. CloudThat is a Microsoft Gold Partner, AWS Advanced Consulting Partner, and a Google Cloud Partner. We will respond quickly to any questions or comments you may have about cloud migration. CloudThat’s Expert Advisory page and Managed Services Package can help you get started.