Search code examples
node.jsbashamazon-web-servicesaws-clicredentials

Why am I having AWS credential errors in my AWS terminal setup?


Wanted to learn AWS and found the tutorial Build a Serverless Web Application. In my research the closest Q&A I could find for my issue was Unable to locate credentials aws cli.

My process has been:

  • Created a repo in Github
  • Navigated to IAM and created a user trainer. Tutorial didn't specify policies so chose AdministratorAccess. Per instructions went the Security credentials and Create access key. Downloaded the file locally.
  • Went to Configuration basics and did Importing a key pair via .CSV file with the command of:
aws configure import --csv file:///Users/path/to/file/aws-training.csv

params:

User name: trainer
Access key ID: ****57
Secret access key: *****1b

but then found that the file didn't contain region or format so did:

aws configure --profile trainer

and re-did all values based on the CSV (Quick Setup):

AWS Access Key ID: ****57
AWS Secret Access Key: *****1b
Default region name: us-east-1
Default output format: json

Made sure to reboot my terminal and locally in a directory I run the command:

aws s3 cp s3://wildrydes-us-east-1/WebApplication/1_StaticWebHosting/website ./ --recursive

The terminal has a delay then throws:

fatal error: Unable to locate credentials

Research

Q&As I've read through to try and see if I could diagnose the problem:

How can I resolve my error of Unable to locate credentials and what am I doing wrong or misunderstanding?


Per the comment:

Check the content of ~/.aws/credentials and ~/.aws/config

credentials

command:

nano ~/.aws/credentials

renders:

[training]
aws_access_key_id = *****57
aws_secret_access_key = ***1b
[trainer]
aws_access_key_id = *****57
aws_secret_access_key = ***1b

config

command:

nano ~/.aws/config

renders:

[profile training]
region = us-east-1
output = json
[profile trainer]
region = us-east-1
output = json

Solution

  • You've configured the profile with the name trainer. You didn't create a default profile, you created a named profile. You're getting the current error because the CLI tool is looking for a default profile, and you don't have one configured.

    In order to use the trainer profile you either have to add --profile trainer to every aws command you run in the command line, or you need to set the AWS_PROFILE environment variable inside your command line environment:

    export AWS_PROFILE=trainer
    

    It looks like you also tagged this with nodejs, so I recommend going the environment variable route, which will also work with the nodeJS AWS SDK.