DEV Community

Darshan Somashekar
Darshan Somashekar

Posted on

Automated deploys with CodePipeline & Elastic Beanstalk

When I launched my site, I created a pretty minimal node app (the main game is all client-side, which is not a topic for this post).

In the beginning, I simply used a cheap $5 Digital Ocean server, and some homemade scripts to push new code from Github to the server. This worked because I didn't have a need for a super mature workflow.

Fast forward a few months, I wanted to launch a new site that focused on Sudoku. Thinking through the architecture, I realized that this site, Sudoku Craze, would have a very similar backend as my original one.

However, by this point I had discovered the shortcomings of my initial setup:

  • Things were brittle. When things didn't work, it was hard to debug.
  • There was a lot of manual setup required to get this pipeline going.

So I began researching how to automate my deployment pipeline. My main goal was to deploy updates to the site with a single push to the GitHub main branch.

To do this, I landed on AWS CodePipeline and AWS Elastic Beanstalk.

I'll walk you through how to get this done.

Create the Elastic Beanstalk environment

-This is easy enough. Log into AWS and navigate to Elastic Beanstalk.

  • Click Create a new environment.
  • Now you'll have to configure your environment. In most cases, you will be building a Web server environment. Select that option.
    • Fill out your application details. First fill out the name. Stick with the Managed image, and then choose the Platform (for me that's Node on 64-bit Amazon Linux 2, latest version).
  • Next, choose Sample Application. In the next section, we'll demonstrate how to update this.

There are additional, advanced configuration options - like being part of a VPC, having a load-balanced app, etc. If you know what you're doing here you should go ahead and select the correct options. For our purposes, we'll just click Create Environment and keep going.

Set up CodePipeline

Now we'll set up the fun part - automated CI/CD deployments.

  • Navigate to AWS CodePipeline Click Create Pipeline
  • Name the pipeline. Everything else, keep as default. Click Next.
  • In the next step, you tell CodePipeline where your code is. For me, that's Github. Select Github (Version 2), and then go through the authentication flow so Github is connected to the pipeline.
  • Then choose your repository and branch that you want CodePipeline to observe. Whenever something is pushed to that repo/branch, CodePipeline will deploy.
  • Everything else, keep as default.
  • For Build Provider, choose CodeBuild.
  • You'll need to create a new project (follow the steps to do so - other than name keep everything else as default).
  • Skip the remaining fields and click Next.
  • Now you'll be at the Deploy stage. This is easy - choose Elastic Beanstalk and then the environment you created in the first section of this article.
  • Once you're done here, review your pipeline and then create it.

Try it

To see if it works, commit something to your repo. Go to the pipeline in CodePipeline, and you should see the pipeline running. Once it finishes deployment, you should now see the app in your Elastic Beanstalk environment.

That's it! This simple set up allowed me to create a lot of easy to use CI/CD pipelines, for Spider, Sudoku, and now Mahjong. Thanks for reading!

Top comments (0)