trek10inc / awsume

A utility for easily assuming AWS IAM roles from the command line.
https://awsu.me
MIT License
497 stars 90 forks source link

Set AWS_REGION as defined in `~/.aws/config` configuration file #14

Closed felipe1982 closed 6 years ago

felipe1982 commented 6 years ago

awsume unsets AWS_REGION, but tools like ec2.py (from Ansible) requires the region to be set. I often prefer the Environment variable AWS_REGION to --region specified on the command line.

Since awsume knows the Region (awsume -l prints it) can it set AWS_REGION environment variable?

mbarneyjr commented 6 years ago

The environment variable AWS_REGION should be getting set when Awsume is run, if it finds a region in the given profile. Awsume unsets all AWS environment variables prior to setting them in order to maintain consistency within your environment under one profile. If Awsume does not find a region in the profile, then the AWS_REGION environment variable will not be set.

So first I'd make sure that you have the region set in your ~/.aws/config file for the profile you're trying to use. If you have a region in your config file and the environment variable is still not being set, then it may be due to a caching issue. Awsume might have cache'd your credentials from that profile from when the region wasn't in the config profile, so it's using the cache'd credentials instead of refreshing it. You could try running awsume <profile_name> -r to force-refresh the credentials.

If you have the region set in your config profile, and you're sure that you're using refreshed credentials, then there is an issue with Awsume, and I'd like to resolve that for you.

What platform are you running Awsume in? Windows/Mac/Linux? And what shell do you use? I would also make sure that you are using the latest version of Awsume, which is currently 1.3.0.

felipe1982 commented 6 years ago

awsume -l

$ awsume -l

=========================AWS Profiles========================
PROFILE                 TYPE  SOURCE     MFA?  REGION
ca-master               User  None       No    ap-southeast-2
default                 User  None       No    ap-southeast-2
itoc                    User  None       Yes   None
itoc-preprod            Role  ca-master  Yes   ap-southeast-2
mycli                   User  None       No    ap-southeast-2
myuser                  User  None       No    ap-southeast-2
osssio-audit            Role  itoc       Yes   None
osssio-consbilling      Role  itoc       Yes   None
osssio-dev              Role  itoc       Yes   None
osssio-ops              Role  itoc       Yes   None
osssio-prod             Role  itoc       Yes   None
osssio-qldonline        Role  itoc       Yes   None
osssio-sandpit          Role  itoc       Yes   None
osssio-staging          Role  itoc       Yes   None
osssio-test             Role  itoc       Yes   None
seeingmachines-preprod  Role  ca-master  Yes   ap-southeast-2

I am running in cygwin without psutil (I commented out those sections of the code). Manually updating credentials is fine for me. Version 1.2.7. Shell is GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin). Python is Python 2.7.13

mbarneyjr commented 6 years ago

The current version is 1.3.0. Please update your installation of Awsume and let me know if your AWS_REGION environment variable is still not being set.

felipe1982 commented 6 years ago

It appears to be working with latest version. Please close. Thanks.

On Sat, Oct 14, 2017, 3:35 AM Michael Barney Jr notifications@github.com wrote:

The current version is 1.3.0. Please update your installation of Awsume and let me know if your AWS_REGION environment variable is still not being set.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/trek10inc/awsume/issues/14#issuecomment-336518665, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQ0pRPxVnDgCAFdcKgbogh6DuY05N8aks5sr59MgaJpZM4PzWsX .

--

Cheers, Felipe