Skip to content

Instantly share code, notes, and snippets.

@RobertoSchneiders
Last active October 29, 2024 19:38
Show Gist options
  • Save RobertoSchneiders/9e0e73e836a80d53a21e to your computer and use it in GitHub Desktop.
Save RobertoSchneiders/9e0e73e836a80d53a21e to your computer and use it in GitHub Desktop.
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
@kevin-coyle
Copy link

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

This works for me

@jkaldenbach
Copy link

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
Copy link

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

@rahul-raina
Copy link

rahul-raina 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
Copy link

theoutlander 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
Copy link

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

@molayodecker
Copy link

molayodecker commented Mar 30, 2020

I am get this error
ERROR: InvalidProfileError - The config profile (default) could not be found

This error means that is need to set the Environment variables for AWS on CircleCI. Which i have done. I even went under Permissions to set my aws Permissions. I even created a script to copy my aws credentials but nothings seems to work

            - run: 
                name: Create aws credentials
                command: |
                    chmod +x ./setup-eb.sh
                    bash ./setup-eb.sh
            - run:
                name: Deploying
                working_directory: /
                command: |
                    eb deploy TcwlApp-env
script 
#!/usr/bin/env bash

set -x
set -e

mkdir ~/.aws
touch ~/.aws/config
chmod 600 ~/.aws/config
echo "[profile prod]" > ~/.aws/config
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >> ~/.aws/config
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> ~/.aws/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment