How to setup Elastic Beanstalk Deployment?

elasticbeanstalk
circle.yml

#1

I can’t figure out how to setup elastic beanstalk on CirclCI.

I have two brunch, which is master and staging.
As you can see, master means production environment and staging means development.

First I set up environment variable like this.

And next, made circleci.yml like this.

machine:
  python:
    version: 2.7.6

dependencies:
  pre:
    - pip install awsebcli
    - printenv

database:
  override:
    - exit 0

test:
  override:
    - exit 0

deployment:
  staging:
    branch: staging
    commands:
      - eb deploy vegewel-staging
  production:
    branch: master
    commands:
      - eb deploy vegewel

And also set up .elasticbeanstalk/config.yml like this.

branch-defaults:
  master:
    environment: vegewel
  staging:
    environment: vegewel-staging
global:
  application_name: vegewel
  default_ec2_keyname: vegewel
  default_platform: 64bit Amazon Linux 2016.03 v2.1.6 running Ruby 2.3 (Passenger
    Standalone)
  default_region: ap-northeast-1
  profile: eb-cli
  sc: git

But every time I check on circleci console, I’ve been facing this problem.

eb deploy vegewel-staging
ERROR: The config profile (eb-cli) could not be found

Any idea? Thanks in advance.


#2

I almost forgot. I already set up AWS credentials. Here’s the image.


#3

I noticed
profile: eb-cli
is cause of error. It attaches local environment.
When I delete this, it works.


#4

It seems that the missing /home/ubuntu/.aws/config file causes the error message "ERROR: The config profile (eb-cli) could not be found"
I followed instructions in the following gist: https://gist.github.com/RobertoSchneiders/9e0e73e836a80d53a21e, which resolved the issue by explicitly creating this file.
I created ./scripts/deploy.sh file with the following content:

#!/usr/bin/env bash
set -x
set -e

AWS_CONFIG_FILE=$HOME/.aws/config

mkdir $HOME/.aws
touch $AWS_CONFIG_FILE
chmod 600 $AWS_CONFIG_FILE

echo "[profile eb-cli]"                              > $AWS_CONFIG_FILE
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID"         >> $AWS_CONFIG_FILE
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> $AWS_CONFIG_FILE

eb deploy my-environment-production 2>&1 | tee $CIRCLE_ARTIFACTS/eb_deploy_output.txt
# Temporary hack to overcome issue eith 'eb deploy' returning exit code 0 on error
# See http://stackoverflow.com/questions/23771923/elasticbeanstalk-deployment-error-command-hooks-directoryhooksexecutor-py-p
grep -v -c -q -i error $CIRCLE_ARTIFACTS/eb_deploy_output.txt

and then in circle.yml I put:

deployment:
  production:
    branch: master
    commands:
      - ./scripts/deploy.sh

HTH


#5

Another solution is simply:

AWS_EB_PROFILE=default eb deploy <environment>

#6

I recently blogged about this: https://blog.cmgresearch.com/2017/05/07/step-5-use-circleci-to-deploy-to-elastic-beanstalk.html - You can also just do:

eb deploy --profile default

#7