M. K. Hunter
M. K. Hunter

Reputation: 1828

Why does the AWS CLI error "You must specify a region." occur when I have a region specified in the ~/.aws/config file?

For AWS CLI configuration and credentials files how do you connect the entries in these files? It is like my credentials work, but my config file does not, though the default profile works.

I am presently getting an error: You must specify a region. You can also configure your region by running "aws configure" when running something like:

aws ec2 describe-instances --profile devenv

However if I run the command:

aws s3api list-buckets --profile devenv

then I get a sensible response, a list of buckets.

Here are the credentials and config files:

~/.aws/credentials

[default]
aws_access_key_id = AAAAAAAAAA
aws_secret_access_key = BBBBBBBBBB

[devenv]
aws_access_key_id = CCCCCCCCCC
aws_secret_access_key = DDDDDDDDDD

[testenv]
aws_access_key_id = EEEEEEEEEE
aws_secret_access_key = FFFFFFFFFF

~/.aws/config

[default]
region = us-east-1
output = json

[devenv]
region = us-west-2
output = json

[testenv]
region = us-east-2
output = json

Upvotes: 2

Views: 4057

Answers (1)

M. K. Hunter
M. K. Hunter

Reputation: 1828

The problem here is the attention paid to constructing the ~/.aws/config file. The "default" entry does not need to be prefaced by the word "profile". The non-default entries need a "profile" prefix. Because the default doesn't require the word "profile," while it works, manually constructed, or built using the aws configure command, it is not a model for the format the other entries require.

~/.aws/config

[default]
region = us-east-1
output = json

[profile devenv]
region = us-west-2
output = json

[profile testenv]
region = us-east-2
output = json

Upvotes: 4

Related Questions