CI/CD in your serverless application using Bitbucket Pipeline

Simran Kaur Kahlon
Gray Matrix
Published in
3 min readJun 9, 2019

CI CD Pipeline implementation or the Continuous Integration/Continuous Deployment software is the backbone of the modern DevOps environment.

We will be leveraging the CI/CD pipeline provided by Bitbucket.

I will be deploying my application on AWS. It has frontend built in React and backend as lambda functions written in node js.

I have used the serverless framework for my backend.

The front end would be deployed in s3 bucket and the backend would be deployed through serverless as lambda functions.

I have 2 bitbucket repositories created for frontend and backend both.

We would be creating two different pipelines for each, i.e the frontend and the backend.

Pipeline for Frontend:

  1. Go to your bitbucket repo and select “Pipeline” from the left nav as :

2. You need to select a language template as :

In my case it’s JavaScript, you could select appropriately. There are other templates available as well in the dropdown on the right.

3. Add the below code in the bitbucket-pipelines.yml file :

Here, we have the pipeline created for 2 branches i.e development and uat.

In case if any commits are made to either of the 2 branches the respective pipeline code will get executed.

I am installing npm, creating a build to be deployed on the s3 bucket and running the automated test cases.

Only if the test cases are successful, the code will be deployed or else the pipeline execution will fail.

The $AWS_KEY,$AWS_SECRET,$DEV_BUCKET,$UAT_BUCKET are variables to be used in the YAML file or script.

  • $AWS_KEY — contains the AWS Key
  • $AWS_SECRET — contains the AWS Password
  • $DEV_BUCKET — is my development bucket name.
  • $UAT_BUCKET — is my uat bucket name.

We can create them by clicking on the variable icon on the right side:

Once you are done, you can commit this file. Make sure to add it in your branches.

In my case, I have the YAML file in both development and uat branch.

Pipeline for Backend:

Likewise, I have a pipeline created for my backend with the following content :

Here, there are a few additional installations and the rest is the same as frontend.

We have serverless and other dependencies installed and have the test cases running.

The $AWS_KEY,$AWS_SECRET,$DEV_ENV,$UAT_ENV are variables and could be created as explained above.

  • $DEV_ENV — is the stage name to be given for development branch deployment
  • $UAT_ENV — is the stage name to be given for uat branch deployment

Again, make sure to commit your file in branches where you wish to have the pipeline executed.

Using CI/CD pipeline makes life much easier since we are not bothered about the deployment part. Also, we have automated test cases running which makes sure that only valid code gets deployed and the existing code remains untouched in case of any failure.

Please get in touch in case of any queries.

Thanks.

--

--

Simran Kaur Kahlon
Gray Matrix

JS/ Laravel / AWS / Chatbot Developer #AWS Solution Architect Associate #AWS Developer Associate