trek10inc / awsume

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

Variables are not exported with pyenv #22

Closed teekaay closed 6 years ago

teekaay commented 6 years ago

I am using pyenv as my version manager. When executing awsume it will print out

$ awsume -s my-profile
User profile credentials will expire: 2018-02-02 22:25:56
Role profile credentials will expire: 2018-02-02 20:12:17+01:00
export AWS_SECRET_ACCESS_KEY=ACCESSKEY
export AWS_ACCESS_KEY_ID=KEYID
export AWS_SESSION_TOKEN=SOMESESSIONTOKEN
export AWS_SECURITY_TOKEN=SOMETOKEN
export AWS_REGION=eu-central-1
export AWS_DEFAULT_REGION=eu-central-1
export AWSUME_PROFILE=my-profile

However, when I call awsume my-profile and then try to print out one of the variables, they are empty. Using $(awsume -s my-profile) instead makes it work. I suppose this has something to do with the way pyenv handles executables. The relevant line is

exec "/home/me/.pyenv/libexec/pyenv" exec "$program" "$@"

which as far as I understand starts a subshell and prevents the variables from being exported.

Is there a way to make awsume work with pyenv or am I doing something wrong?

mbarneyjr commented 6 years ago

The first thing I would look for if your variables aren't being set is the alias for awsume.

Awsume's shell script must be sourced when executed so that the environment variables will be set to the current shell, instead of creating a subshell, setting the subshell's environment variables and closing the subshell.

Awsume's installation should have put an alias definition in your .bashrc, .bash_profile, etc. for you that looks like this:

alias awsume=". awsume"

Some users didn't have one of those files on their system when they installed awsume, in which case you could create the file and reinstall awsume. If that exists in one of your login files, then check to make sure the alias exists by running alias to list your current shell's aliases. Also note that once you install awsume, you may need to open a new terminal for the alias to be set by the login file.

If everything looks good, but is still not working please let us know!

teekaay commented 6 years ago

Thanks for your advice, I really was missing the alias entry in my bashrc. This issue can be closed!