-
Notifications
You must be signed in to change notification settings - Fork 41
AWS Assume Role script improvements #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
letic
commented
Jan 2, 2019
- Make the script more modular no need to hardcode value anymore
- Get the user's AWS CLI credentials
- Ability to choose from different AWS profile (could be easily added as a parameter with getopts but didn't wanted to spend too much time on this)
- Get the user's AWS CLI credentials - Ability to choose from different AWS profile (could be easily added as a parameter with getopts but didn't wanted to spend too much time on this)
| unset AWS_SESSION_TOKEN | ||
| export AWS_ACCESS_KEY_ID=$(grep -A2 "\[$AWS_PROFILE\]" ~/.aws/credentials | awk -F"= " '/aws_access_key_id/ {print $2}') | ||
| export AWS_SECRET_ACCESS_KEY=$(grep -A2 "\[$AWS_PROFILE\]" ~/.aws/credentials | awk -F"= " '/aws_secret_access_key/ {print $2}') | ||
| export AWS_REGION=$(grep -A2 "\[$AWS_PROFILE\]" ~/.aws/config | awk -F"= " '/region/ {print $2}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the grep/awk flows are effectively the same, would it make sense to move the logic to a function and just pass in aws_access_key_id, aws_secret_access_key, region as the differentiator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course that would be cleaner.
| if [ ! -z "$3" ]; then | ||
| AWS_SESSION_NAME=$3 | ||
| else | ||
| AWS_SESSION_NAME="Assume-$1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to assign $1 to a variable (e.g. AWS_ID) just for clarity, especially later where you reference $1 as part of the assume role line (it makes that line just a little bit clearer).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure good idea 👍
I also thought that we should add a parameter to revert the credentials to the default AWS profile.
Looking forward to your improvements.