Auto deploy AWS Lambda (serverless) Using bitbucket pipelines
In this article we will learn to auto deploy aws lambda serverless application using bitbucket pipelines.
Prerequisites:
- AWS Account
- bitbucket account and repository where you push your code
- 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.
Step 2:
Add the following code in you YML file.
- node:12 — is the docker image that i’m using, add version of node or any other according to your requirements.
- Under branches i have mentioned the authorizer branch for deployment.
- 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.
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
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