aws / aws/aws-cli

AWS CLI exits successfully when unable to read from credentials file using `aws configuration get`

Open
#2,565 1 comment 0 reactions 0 assignees View on GitHub
automation-exempt configuration confusing-error enhancement feature-request p3
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

This is very easy to reproduce, and happened to me as a result of copying a credential file from another mount and not owning the file with my current user.

If for some reason, the user executing the aws command doesn't have file access to `~/.aws/credentials` the CLI will exit 0 and echo nothing. If it so happens that you do not define a `[profile ]` for a `[]` entry in ~/.aws/credentials AWS CLI cannot even see the values and gives you an error that the profile doesn't exist (it does).

Here is the fullest example I can produce:
```
➜ cosmos-hash-circuit git:(master) ✗ aws configure
AWS Access Key ID [None]: default_key
AWS Secret Access Key [None]: default_secret
Default region name [None]: us-east-1
Default output format [None]: json
➜ cosmos-hash-circuit git:(master) ✗ cat ~/.aws/config
[default]
output = json
region = us-east-1
➜ cosmos-hash-circuit git:(master) ✗ gvim ~/.aws/credentials
➜ cosmos-hash-circuit git:(master) ✗ sudo chown root:root ~/.aws/credentials
➜ cosmos-hash-circuit git:(master) ✗ sudo cat ~/.aws/credentials
[default]
aws_secret_access_key = default_secret
aws_access_key_id = default_key

[foo]
aws_secret_access_key = default_foo_secret
aws_access_key_id = default_foo_key
➜ cosmos-hash-circuit git:(master) ✗ aws configure get aws_access_key_id
➜ cosmos-hash-circuit git:(master) ✗ aws configure get aws_access_key_id --profile foo

The config profile (foo) could not be found
➜ cosmos-hash-circuit git:(master) ✗ aws configure get profile.foo.aws_access_key_id
➜ cosmos-hash-circuit git:(master) ✗ sudo aws configure get aws_access_key_id
default_key
➜ cosmos-hash-circuit git:(master) ✗ sudo aws configure get aws_access_key_id --profile foo
default_foo_key
➜ cosmos-hash-circuit git:(master) ✗
➜ cosmos-hash-circuit git:(master) ✗ sudo aws configure get profile.foo.aws_access_key_id
default_foo_key

```
It was pretty frustrating when I realized what the problem was the whole time. It would have been nice if the CLI simply told me that it could not read from the file.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.