aws-cli in a Github Actions workflow keeps prompting for credentials despite those being already set?

Viewed 1190

I'm wanting to run aws configure in a Github Actions Workflow to set up a deployment pipeline. However, in contrast to the docs found here, setting the environment variables does not seem to work.

Example job:

deploy: name: Test AWS cli runs-on: ubuntu-latest

steps:
  - name: Checkout
    uses: actions/checkout@v2

  - name: Configure AWS credentials
    uses: aws-actions/configure-aws-credentials@v1
    with:
      aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      aws-region: us-west-2

  - name: Copy files to S3 with the AWS CLI
    run: |
      which aws
      aws configure

Results in

EOF when reading a line
AWS Access Key ID [********************]: 
##[error]Process completed with exit code 255.

Which, when reproduced locally, is because it prompts for the access key ID from the aws-cli.

Why does it prompt me for it, when, according to the docs for it, it should pick up the environment variable and set it accordingly?

The secrets have been set up inside Github with the correct naming that is referenced to above.

1 Answers

aws-actions/configure-aws-credentials@v1 didn't work for me either. Here is how you setup your AWS Credentials. As of 7/05/2021 Ubuntu latest comes with the Aws CLI pre-installed so you can just set variables of AWS CLI using the Github Actions "Environment Variables". Declare your environment variables with env: after choosing what system to run your workflow on. You can still use your GitHub Secrets and also for the region although I declare it explicitly in my example.

runs-on: ubuntu-latest
env:
  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  AWS_DEFAULT_REGION: us-west-1
steps:
- uses: actions/checkout@v2

This will setup AWS CLI environment variables for you and there is no longer any need to use aws-actions/configure-aws-credentials@v1 to setup your AWS Credentials. Make sure to put your AWS credentials in your GitHub Secrets located in the Settings of your repo. When using secrets. in environment variable GitHub will know to look in your repository secrets for any ones that match the secret name you give

Related