Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Settings to deploy to AWS Elastic Beanstalk on CircleCi (EB Cli 3)

This is how I configured the deploy of my rails apps to AWS Elastic Beanstalk through CircleCI 1.0.

If you are using the Circle CI 2.0, take a look at this article from ryansimms

Configure Environments Variables

On Project Settings > Environment Variables add this keys:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
    The aws user must have the right permissions. This can be hard, maybe, this can help you.

Create a bash script to create the eb config file

./setup-eb.sh

set -x
set -e

mkdir /home/ubuntu/.aws
touch /home/ubuntu/.aws/config
chmod 600 /home/ubuntu/.aws/config
echo "[profile eb-cli]" > /home/ubuntu/.aws/config
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >> /home/ubuntu/.aws/config
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> /home/ubuntu/.aws/config

Configure circle.yml

Add the awsebcli dependency:

dependencies:
  pre:
    - sudo apt-get update
    - sudo apt-get install python-dev
    - sudo pip install awsebcli

Add the deployment config:

deployment:
  production:
    branch: master
    commands:
      - bash ./setup-eb.sh
      - eb deploy
  • If your deploy user don't have the elasticbeanstalk:DescribeEvents permission, the eb deploy will run for ever. CircleCI will cancel it after 10 minutes and break the build with timeout.

Create the EB Cli config file

eb init will create this file for you. However, if you don't want to run it, you can simply create and configure this file manualy:

./elasticbeanstalk/config.yml

branch-defaults:
  master:
    environment: you-environment-name
global:
  application_name: your-application-name
  default_ec2_keyname: ec2-key-pair-name
  default_platform: 64bit Amazon Linux 2015.03 v1.4.3 running Ruby 2.2 (Puma)
  default_region: sa-east-1
  profile: eb-cli
  sc: git
@axwalker

This comment has been minimized.

Copy link

commented Sep 4, 2015

Thanks for this! After adjusting the permissions on my policy for ages, I finally managed to get my builds passing using both codeship and Span CI, but they still just left EB hanging indefinitely. Your IAM policy fixed the issue on both.

@dvrajan

This comment has been minimized.

Copy link

commented Oct 23, 2015

Thanks for sharing this. Really helpful!

@euharrison

This comment has been minimized.

Copy link

commented Nov 5, 2015

Thanks! Very useful! I realized that if you fill the AWS KEY and SECRET in the CircleCI site, you can remove the bash ./setup-eb.sh and just use the command eb deploy --profile default because CircleCI creates this profile automatically

deployment:
  production:
    branch: master
    commands:
      - eb deploy --profile default
@johnh

This comment has been minimized.

Copy link

commented Dec 8, 2015

Thanks for this gist - the most straightforward solution to simply having Circle automate the EB deploy. Also +1 for euharrison's comment about the KEYS in yoru circle setup.

@vasco3

This comment has been minimized.

Copy link

commented Mar 7, 2016

tried to deploy using artifacts but the eb config couldn't understand the $CIRCLE_ARTIFACT environment variable. It would take it as a string instead of a variable

@tomw

This comment has been minimized.

Copy link

commented Apr 8, 2016

This has been working fine for a few months, but since yesterday evening fails on sudo pip install awsebcl', with the error OSError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/setuptools-3.4.4-py2.7.egg'. Have any of you seen this problem?

@mathieudutour

This comment has been minimized.

Copy link

commented Apr 11, 2016

I did, just replace sudo pip install awsebcli by sudo pip install awsebcli --ignore-installed setuptools

@jmfurlott

This comment has been minimized.

Copy link

commented Apr 12, 2016

@tomw I only just started getting this issue, as well. I wonder what changed?

@erikahlswede

This comment has been minimized.

Copy link

commented Apr 13, 2016

They released a new version and PIP is failing to fully uninstall the previous version.

sudo pip install 'awsebcli==3.7.4' --force-reinstall

Is what I use

@LevBravE

This comment has been minimized.

Copy link

commented Apr 22, 2016

Solution

  1. Set Ubuntu 14.04 (Trusty) (Project Settings > Build Environment)
  2. Update the awsebcli dependency
dependencies:
  pre:
    - pip install awsebcli

It seems to fix everything

@allrore

This comment has been minimized.

Copy link

commented Jun 29, 2016

This works for me:

dependencies:
  pre:
    - sudo pip install 'awsebcli==3.7.4' --force-reinstall
deployment:
  production:
    branch: master
    commands:
      - eb deploy --profile default
@mediafreakch

This comment has been minimized.

Copy link

commented Jul 20, 2016

While @allanrr solution returns a fatal error pyconfig.h: No such file or directory, @LevBravE 's works for me too.

@tonyfruzza

This comment has been minimized.

Copy link

commented Oct 8, 2016

To install awsebcli I found that python-dev was required. Here's my dependencies snippet

dependencies:
  pre:
    - sudo apt-get install python-dev
    - sudo pip install awsebcli
@anbestephen

This comment has been minimized.

Copy link

commented Oct 12, 2016

After the below task get executed, i am getting this error message:-

eb deploy --profile default

ERROR: This directory has not been set up with the EB CLI
You must first run "eb init".
@justinthareja

This comment has been minimized.

Copy link

commented Oct 13, 2016

Worked flawlessly with the dependencies snippet from @tonyfruzza.

@anbestephen: I got the same error message, then noticed this snippet in my gitignore

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

which was automatically generated when I ran eb init in my project folder locally, preventing the generated .elasticbeanstalk/config.yml from being commited to my repo. After adding an !.elasticbeanstalk/config.yml exception, Circle Ci ran eb deploy <my_environment> with no problem. Not sure if you're having a similar issue, but EB Cli config file must exist in order to run a deploy.

@mikeghen

This comment has been minimized.

Copy link

commented Nov 8, 2016

This is great, thank you! 👍 🌟

@joemccall86

This comment has been minimized.

Copy link

commented Dec 1, 2016

@justinthareja Why do you think those were in gitignore? Would tracking those files in git them break any recommended best-practices by EB?

@tripper54

This comment has been minimized.

Copy link

commented Jan 18, 2017

@joemccall86 It's probably a good idea to leave those entries in gitignore. This lets you do things like eb ssh into different environments without changing the config in VC.

I got around this by storing a config.yml elsewhere in my codebase and copying into place for circleci:

release:
    tag: /release-.*/
    owner: me
    commands:
      - mkdir .elasticbeanstalk
      - cp resources/circle/eb/config.yml .elasticbeanstalk/config.yml
      - eb deploy --profile default
@vivekna1

This comment has been minimized.

Copy link

commented Mar 13, 2017

@euharrison
I am trying to follow your cue i.e " fill the AWS KEY and SECRET in the CircleCI site, you can remove the bash ./setup-eb.sh and just use the command eb deploy --profile default"
It asks for running eb init and
eb init is stuck without selecting any option, (new to eb commands). What needs to be done here?

@merliecat

This comment has been minimized.

Copy link

commented Apr 12, 2017

@vivekna1
I got the same issue, i.e. I needed to put 'eb init' and the process was halted when it asked for an option.
The solution was to choose an option from the list (for me it was '15: eu-west-2') and then do the following: -
- echo 15 | eb init
I.e. pipe the selected response into the 'eb init' command.

@kevin-coyle

This comment has been minimized.

Copy link

commented Apr 24, 2017

  pre:
    - sudo apt-get install libyaml-dev libpython2.7-dev
    - sudo pip install 'awsebcli==3.7.4' --force-reinstall

This works for me

@jkaldenbach

This comment has been minimized.

Copy link

commented May 25, 2017

To use the current version of awsebcli on the 14.04, I had to install python-dev (solves the Python.H issue) and update pip (solves Import Error: No module named packaging.version):

pre:
    - sudo apt-get install python-dev
    - sudo pip install --upgrade pip
    - sudo pip install awsebcli
@osazemeu

This comment has been minimized.

Copy link

commented Jun 14, 2017

@jkaldenbach was the only solution that worked for me. Thanks guys

@rahul-raina

This comment has been minimized.

Copy link

commented Jun 19, 2017

@osazemeu -- had to end up using easy install

pre:
    - sudo apt-get install python-dev
    - sudo easy_install --upgrade six
    - sudo pip install awsebcli
@theoutlander

This comment has been minimized.

Copy link

commented Nov 1, 2017

Thanks a lot! I had to use a slightly modified version:

#!/usr/bin/env bash
mkdir ~/.aws
touch ~/.aws/config
chmod 600 ~/.aws/config
echo "[profile eb-cli]" > ~/.aws/config
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >> ~/.aws/config
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> ~/.aws/config

Also, specifying the keys in the CircleCI UI made them available only as environment variables. Not sure why it didn't create these files!

@ryansimms

This comment has been minimized.

Copy link

commented Jan 8, 2018

Thanks for this, it was a big help for getting started with deploying to Elastic Beanstalk via CircleCi.

For those coming to this page that want to use CircleCi 2.0 (as I did), I wrote up the steps I took after hours of trial and error, hopefully they'll help someone:

https://gist.github.com/ryansimms/808214137d219be649e010a07af44bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.