AWS credentials during Docker build process

12,173

The name of the environment variable is AWS_ACCESS_KEY_ID vs AWS_ACCESS_KEY

You can review the full list from amazon doc

The following variables are supported by the AWS CLI

AWS_ACCESS_KEY_ID – AWS access key.

AWS_SECRET_ACCESS_KEY – AWS secret key. Access and secret key variables override credentials stored in credential and config files.

AWS_SESSION_TOKEN – session token. A session token is only required if you are using temporary security credentials.

AWS_DEFAULT_REGION – AWS region. This variable overrides the default region of the in-use profile, if set.

AWS_DEFAULT_PROFILE – name of the CLI profile to use. This can be the name of a profile stored in a credential or config file, or default to use the default profile.

AWS_CONFIG_FILE – path to a CLI config file.

Share:
12,173

Related videos on Youtube

Richlewis
Author by

Richlewis

Software Tester Ruby Ruby On Rails HTML CSS Javascript jQuery Follow me on twitter @richl14

Updated on October 12, 2022

Comments

  • Richlewis
    Richlewis over 1 year

    As part of the process to build my docker container I need to pull some files from an s3 bucket but I keep getting fatal error: Unable to locate credentials even though for now I am setting the credentials as ENV vars (though would like to know of a better way to do this)

    So when building the container I run

    docker build -t my-container --build-arg AWS_DEFAULT_REGION="region" --build-arg AWS_ACCESS_KEY="key" --build-arg AWS_SECRET_ACCESS_KEY="key" . --squash
    

    And in my Dockerfile I have

    ARG AWS_DEFAULT_REGION
    ENV AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION
    
    ARG AWS_ACCESS_KEY
    ENV AWS_ACCESS_KEY=$AWS_ACCESS_KEY
    
    ARG AWS_SECRET_ACCESS_KEY
    ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
    
    RUN /bin/bash -l -c "aws s3 cp s3://path/to/folder/ /my/folder --recursive"
    

    Does anyone know how I can solve this (I know there is an option to add a config file but that just seems an unnecessary extra step as I should be able to read from ENV).

    • tayfun
      tayfun over 6 years
      In addition to environment variable name mentioned in an answer below, you also don't need ENV here as you seem to be only needing it in build step. ARG will be enough in this case and variable will not persist in the image.