chef/knife-ec2

Cannot find default region in AWS config file.

Closed this issue · 1 comments

Version:

Knife Version: Chef Infra Client: 15.5.15
knife-ec2 (1.0.16)

Scenario:

We have multiple AWS accounts and have it integrated it with chef. However, It seems the plugin cannot read the default AWS region for a specific profile. It's very annoying having to specify the default region on every command.

When I do..

knife ec2 server list --aws-profile mycompany

It returns an EMPTY result but if I do

knife ec2 server list --aws-profile mycompany --region ca-central-1

It returns everything as normal.

It's annoying having to specify a region and now have it read from the AWS config file. I was pretty sure this once worked a long time ago.

Steps to Reproduce:

cat ~/.chef/config.rb

knife[:aws_credential_file] = File.join(ENV['HOME'], "/.aws/credentials")
knife[:aws_config_file] = File.join(ENV['HOME'], "/.aws/config")

cat ~/.aws/credentials

[mycompany]
aws_access_key_id = 12345
aws_secret_access_key = 67890

[profile  mycompany]
aws_access_key_id = 12345
aws_secret_access_key = 67890

cat ~/.aws/config

[mycompany]
region = ca-central-1

[profile mycompany]
region = ca-central-1

As a temporary workaround, I had to hardcode this in my knife config.rb until I switch profiles.

cat ~/.chef/config.rb

knife[:region] = "ca-central-1"