What’s up Guys! Welcome to automationcalling.com

Lambda_Deployment

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
    • lambda_plugin

Deploy Lambda Code in Jenkins:

  1. Create a FreeStyle Job in Jenkins
  2. Configure where your source code is running in Jenkins
  3. In Build Environment (Execute Shell)
    1. Supply Gradle or Maven Clean build which will generate Jar as zip file under distribution
    2. write a simple Linux command to traverse to the location
    3. Use AWS CLI command to copy your zipe file from local to S3 location, for eg.,
      1. aws s3 cp test-lambda.zip s3://test-lambda-operation/test-lambda.zip
  4. In Post Build Action -> Select “AWS Lambda Deployment” plugin and Fill the appropriate information like below examples
    1. lambda_configuration
    2. Lambda Plugin also has capability to update Environment Variable and Subnet and Security Details (In case your lambda needs to run under VPC)
      1. environmentvar
  5. Click on the Save button.
  6. 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! 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s