How to run aws configure in a travis deploy script?

I am trying to get travis-ci to run a custom deploy script that uses awscli to push a deployment up to my staging server.

In my .travis.yml file I have this:

before_deploy:
  - 'curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"'
  - 'unzip awscli-bundle.zip'
  - './awscli-bundle/install -b ~/bin/aws'
  - 'export PATH=~/bin:$PATH'
  - 'aws configure'

And I have set up the following environment variables:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION

with their correct values in the travis-ci web interface.

However when the aws configure runs, it stops and waits for user input. How can I tell it to use the environment variables I have defined?

Answers 1

  • You can set these in a couple of ways.

    Firstly, by creating a file at ~/.aws/config (or ~/.aws/credentials).

    For example:

    [default]
    aws_access_key_id=foo
    aws_secret_access_key=bar
    region=us-west-2
    

    Secondly, you can add environment variables for each of your settings.

    For example, create the following environment variables:

    AWS_DEFAULT_REGION
    AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY
    

    Thirdly, you can pass region in as a command line argument. For example:

    aws eb deploy --region us-west-2
    

    You won't need to run aws configure in these cases as the cli is configured.

    There is further AWS documentation on this page.


Related Articles