Setting up continuous deployment to Elastic Beanstalk

Posted on December 22, 2013

We’ve been looking into setting up continuous integration and deployment at work. While the integration part of things is more or less a known quantity, the deployment side of things is a bit more challenging. I’ve had great success with Elastic Beanstalk thus far, and I wanted to find a way to use CI and then deploy good builds to Beanstalk. For reference, we’ve been using Codeship and have had really great experiences with them. I’ve cobbled these instructions together on my own from a number of different sources, including this post from Snap.

  1. Set up your Elastic Beanstalk environment, and deploy to it at least once. (If you use the sample application when you first create it, the S3 bucket won’t be instantiated.)
  2. Make sure you have the AWS CLI installed, and that you have your AWS credentials and everything running.
  3. Run this command:
    aws elasticbeanstalk describe-application-versions --application-name "YOUR APP NAME"

    and you should get something like this:

        "ApplicationVersions": [
                "ApplicationName": "YOUR APP NAME",
                "VersionLabel": "a1b2c3d",
                "SourceBundle": {
                    "S3Bucket": "elasticbeanstalk-us-east-1-11111111",
                    "S3Key": "YOUR APP/"
                "DateUpdated": "2013-12-22T22:23:08.886Z",
                "DateCreated": "2013-12-22T22:23:08.886Z"
  4. From that we want the S3 bucket, as that’s what we’ll be deploying to.
  5. Here are the commands you need to run to set up a deployment:
    pip install awscli
    zip -r . -x "*.git*" "*vendor*"
    aws s3 cp s3://elasticbeanstalk-us-east-1-11111/YOUR APP/git-`git rev-parse --short HEAD`.zip --region "us-east-1"
    aws elasticbeanstalk create-application-version --application-name "YOUR APP" --version-label `git rev-parse --short HEAD` --source-bundle S3Bucket="elasticbeanstalk-us-east-1-11111",S3Key="YOUR APP/git-`git rev-parse --short HEAD`.zip" --region "us-east-1"
    aws elasticbeanstalk update-environment --environment-name "yourapp-env" --version-label `git rev-parse --short HEAD` --region "us-east-1"
  6. What’s going on here?
    1. First, install the AWS CLI
    2. Next, take everything in the directory and zip it together. I exclude the .git and vendor directories (the latter because this is PHP), but you should tailor this to whatever you want.
    3. Then upload the zipped file to the S3 bucket. The use of git rev-parse --short HEAD just gets you the short version of the commit hash.
    4. Create an application version in  your app that uses the uploaded zip file. Give it a version label that matches the git commit hash.
    5. Deploy that version to your environment.
  7. Update those lines and set them into whatever setup you’re using for deployment.

Hopefully this helps. This may not work as is for everyone, and you’ll probably have to tweak it a bit – but it’s a start.

One response to “Setting up continuous deployment to Elastic Beanstalk”

  1. […] on a previous post about doing continuous deployment to Elastic Beanstalk, I just did a setup to get Play Framework to […]

Leave a Reply

Your email address will not be published. Required fields are marked *