Last active
May 26, 2017 03:02
-
-
Save nicka/19d4a0a30a1debed2c287b5fe94ff66d to your computer and use it in GitHub Desktop.
Assumes an AWS IAM role and exports temporary AWS_* credentials.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### Description: Assumes an AWS IAM role and export temporary AWS_* credentials. | |
#### Written by: Nick den Engelsman - [email protected] on 2017-05 | |
#### | |
#### Setup: | |
#### 1. npm install -g aws-auth-helper | |
#### 2. save this script as ~/.aws/mfa.sh | |
#### 3. chmod +x ~/.aws/mfa.sh | |
#### | |
#### Edit your .bash_rc (or something else): | |
#### alias aws-auth="source ~/.aws/mfa.sh $1" | |
#### | |
#### Usage: | |
#### aws-auth [PROFILE] | |
# Make sure previous sessions are cleaned | |
AWS_ACCESS_KEY_ID="" | |
AWS_SECRET_ACCESS_KEY="" | |
AWS_SESSION_TOKEN="" | |
# Configure the aws auth helper | |
AWS_CONFIG_FILE="~/.aws/config" | |
AUTH_HELPER=$(which aws-auth-helper) | |
# Obtain credentials | |
eval `$AUTH_HELPER $1` | |
# Export newly obtained credentials | |
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID | |
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY | |
export AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment