Auto deploy AWS Lambda (serverless) Using bitbucket pipelines

Muhammad Asad Attari
3 min readJul 18, 2022

--

In this article we will learn to auto deploy aws lambda serverless application using bitbucket pipelines.

Prerequisites:

  1. AWS Account
  2. bitbucket account and repository where you push your code
  3. Locally configured serverless application

Instead of pushing code and deploying code separately, push your code to bitbucket and bitbucket will look after your deployments when you push your code. Let’s start without wasting time

Step 1:

Create bitbucket-pipelines.yml file in root level of your repository.

bitbucket-pipelines.yml

Step 2:

Add the following code in you YML file.

Pipelines code
  1. node:12 — is the docker image that i’m using, add version of node or any other according to your requirements.
  2. Under branches i have mentioned the authorizer branch for deployment.
  3. Under script i define the order of scripts in which code will deploy.

NOTE: Under Script, in 3rd command i have passed -p (Provider) which is aws, -k (key) aws Access Key ID and secret which is aws secret key id, which you can generate from

  • AWS Management Console → Identity and Management Console (IAM) → Users → then Select User → under security credentials → create access key
  • Copy the Access key and Secret key to the clip board once appeared.
  • Go to your bitbucket repository and enable the pipelines under pipelines → settings.

Step 3:

Create Repository Variables after Enabling Pipelines.

Repository Variables
Create variables

Note: Remember your keys here and in .yml file should be same.

Step 4:

It’s time to see all in action,

Push your bitbucket-pipelines.yml file to your target branch which you have selected for deployment, the bitbucket-pipelines.yml file will triggered pipelines and auto deploy your code. you will see like below

pipeline status

Note: If Your Pipeline successfully runs then you will see status successful and if failed then see status Failed.

Conclusion

In this article we have seen that how to deploy Serverless AWS lambda function using bitbucket-pipelines. If you have any confusion or question please comment. thanks

--

--

Muhammad Asad Attari
Muhammad Asad Attari

Written by Muhammad Asad Attari

Software Engineer | Full Stack Developer | DevOps Engr.

No responses yet