Continuous Deployment to Lambda function using Bitbucket pipeline

Please visit my website and subscribe to my youtube channel for more articles

https://devops4solutions.com/

In this blog, we will setup the Continuous Deployment to Lambda function using Bitbucket pipeline

CI/CD Flow:

  1. Docker image
  2. We are using caches feature of bitbucket pipeline. We are doing custom caching for node_modules folder
  3. Run the npm install command
  4. Creating a zip file

5. Upload zip file to S3 bucket

6. Update the lambda function that will take the new artifacts from S3 buckets

Prerequisite:

  1. S3 bucket on AWS
  2. Lambda function
  3. IAM Role
  4. bitbucket-pipeline.yaml file
  5. AWS Secret Keys
  6. Environment Variables

How to setup a Continuous Deployment to Lambda function using Bitbucket pipeline

  1. Create a bitbucket-pipeline.yaml file at the root of your project
  2. For the specific bitbucket repository -> Go to Settings -> Add Repository variables
AWS_SECRET_ACCESS_KEY
AWS_ACCESS_KEY_ID
AWS_REGION
AWS_LAMBDA_FUNCTION_NAME
AWS_ROLE

All the above variables are required to connect to s3 bucket and the lambda function from bitbucket pipeline.

3. We are setting up a Continuous Deployment to Lambda function using Bitbucket pipeline for nodejs application

image: lambci/lambda:build-nodejs6.10pipelines:default:- step:deployment: productionscript:- npm install- npm install node-lambda -g- zip test.zip ./node_modules index.js test.js- aws s3 cp test.zip s3://test-bucket-carnival-  aws lambda update-function-code --function-name lambdatest --s3-bucket test-bucket-carnival --s3-key test.zip#- node-lambda deploy -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -o $AWS_ROLE -r $AWS_REGION -n $AWS_LAMBDA_FUNCTION_NAME --excludeGlobs "bitbucket-pipelines.yml"caches:- node

Congratulations, we have successfully setup the Continuous Deployment to Lambda function using Bitbucket pipeline

Written by

Devops Automation Enginneer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store