trek10inc / awsume

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

Show Commands in non-interactive mode? #85

Closed gesellix closed 4 years ago

gesellix commented 4 years ago

When using awsume -s profile in an empty environment, awsume prints token expiry messages just before the desired export statements, e.g. like this:

$ awsume --show-commands --mfa-token 123456 profile
Session token will expire at ...
Role credentials will expire ...
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
export AWS_SECURITY_TOKEN=...
export AWS_REGION=...
export AWS_DEFAULT_REGION=...
export AWSUME_PROFILE=profile

I would like to use --show-commands in scripts, but I only need the export statements. The Session token will expire ... and Role credentials will expire ... messages aren't necessary.

Would be possible to disable the output of those messages? Maybe it would be enough to expose the existing is_interactive argument as command line option?

mbarneyjr commented 4 years ago

Executing the awsume -s commands should function exactly the same as executing awsume.

In scripts executed through certain shells, it might be necessary to source awsume every time it's run (or define an alias to do this at the beginning of your script).

Aside from that, the commands are output to stdout, while the expiration messages are output to stderr

Any of those should help you get to a solution, I'd be interested to hear your use case if not though

gesellix commented 4 years ago

expiration messages are output to stderr

Ah, I need to check that, that would help a lot.

gesellix commented 4 years ago

Redirecting stderr works, thanks!

Regarding my use case: I don't want to clutter my local setup with specific Python, PIP, PIPX or other dependencies, so I always try to wrap everything in a dedicated container (Docker). Side effect is easier cross-platform compatibility.

My progress so far: https://github.com/gesellix/awsume#manage-your-shells-environment