Created
July 19, 2019 17:17
-
-
Save scottrigby/46f069569800027c47465dd372eaa1a5 to your computer and use it in GitHub Desktop.
aws-vault assume role prompt exec for ~/.bash_profile
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
function aws_vault_exec() { | |
if ! which aws-vault >/dev/null; then | |
echo You must have 'aws-vault' installed. See https://github.com/99designs/aws-vault/ | |
return 1 | |
fi | |
local list=$(grep '^[[]profile' <~/.aws/config | awk '{print $2}' | sed 's/]$//') | |
if [[ -z $list ]]; then | |
echo You must have AWS roles and profiles set up to use this. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-cli.html | |
return 1 | |
fi | |
local nlist=$(echo "$list" | nl) | |
while [[ -z $AWS_PROFILE ]]; do | |
local AWS_PROFILE=$(read -p "AWS profile? `echo $'\n\r'`$nlist `echo $'\n> '`" N; echo "$list" | sed -n ${N}p) | |
done | |
echo AWS Profile: $AWS_PROFILE. CTRL-D to exit. | |
aws-vault exec $AWS_PROFILE --assume-role-ttl=1h -- | |
} | |
alias ave="aws_vault_exec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment