What’s up Guys! Welcome to automationcalling.com
In this blog, we are going to take a look at how to deploy a lambda code to AWS using Jenkins Free-Style Job based on the above flow diagram.
The following environment setup/pre-requisites required to achieve the above flow.
- Running Jenkins (Master/Slave) Machines
- SCM (Any – Bitbucket or GitHub) with your Source Code (In this example, I will show Java 8).
- AWS CLI must be installed where Jenkins is running either Master or Slave Machine.
- Identify/Create S3 Bucket Name
- Must-Have AWS Programmatic Access User which should be configured in AWS CLI with its Access Key and Secret Key
- Create a role which has Lambda Execution Access
- Must be Known about what is Lambda Function Name and Handler Name.
- Install Lambda Plugin in Jenkins
Deploy Lambda Code in Jenkins:
- Create a FreeStyle Job in Jenkins
- Configure where your source code is running in Jenkins
- In Build Environment (Execute Shell)
- Supply Gradle or Maven Clean build which will generate Jar as zip file under distribution
- write a simple Linux command to traverse to the location
- Use AWS CLI command to copy your zipe file from local to S3 location, for eg.,
- aws s3 cp test-lambda.zip s3://test-lambda-operation/test-lambda.zip
- In Post Build Action -> Select “AWS Lambda Deployment” plugin and Fill the appropriate information like below examples
- Lambda Plugin also has capability to update Environment Variable and Subnet and Security Details (In case your lambda needs to run under VPC)
- Click on the Save button.
- That’s it, Now Build Jenkins Job
This will kick start the job by copying zip file in local to S3 Object and code/configuration will get updated on AWS. The appropriate configuration and environment details will be updated in AWS Lambda Function.
Note: The above example is one way of deploying Lambda Function to AWS, there are other examples like Terraform, AWS Cloud formation template, Core AWS CLI commands etc., using Jenkins.
Thanks for your time, please do subscribe for more updates!