The Ops Community

Jason Purdy
Jason Purdy

Posted on • Updated on

Automatic EB deployment from git push

AWS has a service called Code Pipeline, which probably has a lot of super special skilz to do amazing things, but they also have a dead-easy yet still powerful feature that will automatically deploy updates to an Elastic Beanstalk environment. What this means is that you can set it up so that it "listens" to a GitHub repository and whenever a branch has an update, it will bundle it all together with a ZIP file and then send the ZIP file to Elastic Beanstalk to go through its deployment steps. Here's how you set it up:

First, you go to add a new Pipeline, which looks a little something like this:

Step 1 of creating a Code Pipeline

After hitting next, you need to setup the Source Stage. At my work, we use GitHub and fortunately, there's a really cool integration with GitHub (Version 2):

Step 2 of creating a Code Pipeline

Once it's connected, you can select your repo and branch and then hit Next. Skip the Build Stage and then for the Deploy Stage, you can select Elastic Beanstalk and then your application and environment target:

Final step in setting up Code Pipeline

Now what's cool is that whenever I push a change up to the main branch, it automatically deploys to that Elastic Beanstalk app/env, which keeps it up-to-date with our latest work.

The pipeline in effect.

There are other repository options like Bitbucket or AWS's own Code Repository, if you have your code elsewhere.

In addition, I would turn on the notifications in Elastic Beanstalk so that it emails you whenever a deployment happens (or if there's a failure). This will give you confidence in that it's actually working as well as you'll know if something broke. You set this up with your environment configuration in the Notifications section:

Notifications settings for Elastic Beanstalk

Discussion (0)