aws-eb

Using Multiple AWS Credential Files for Elastic Beanstalk

At Cinevee, we are developing several forks of our distribution platform for each of our partners. This means we deploy to a different environment in a different AWS account (with differing credentials) for each fork. Re-initializing Elastic Beanstalk eb init before you git aws.push can get annoying when you are switching back forth between projects a dozen times a day (we’re quite agile). So here’s a quick way to setup and switch between your AWS credential files per project.

  1. Create a simple text file and save it in your git repo as ‘AWS_CREDENTIAL’ with:
    AWSAccessKeyId=Write your AWS access ID
    AWSSecretKey=Write your AWS secret key

    replacing your AWS access ID and secret key.

  2. Limit file permissions with:
    chmod 600 <file path to AWS_CREDENTIAL>
  3. Set the AWS credential environment variable with
    export AWS_CREDENTIAL_FILE=<file path to AWS_CREDENTIAL>

    replacing the file path to the text file you created in step 1.

  4. Instead of typing “export AWS_CRED…” every time you switch between projects, you can create an alias in Terminal by updating your .bash_profile found at “Users/<USERNAME>/.bash_profile”. Add:
    alias AWS-Project1="export AWS_CREDENTIAL_FILE=<file path to AWS_CREDENTIAL for project1>"
  5. Repeat this alias line for each project, updating the alias command “AWS-Cinevee” and the AWS_CREDENTIAL file path for each entry.

Information used from the AWS CLI Tools docs.

  • pynzrz

    This doesn’t work. How can you verify whether the credentials were successfully switched? When I check eb init, it’s still the old credentials.

  • davelassanske

    After you enter the alias in Terminal, if you type ‘eb status’ while in your Elastic Beanstalk project directory you shouldn’t be asked to re-init EB.

    Are you entering into Terminal the alias you defined in your .base_profile (for example ‘AWS-Project1’)?