Created
January 17, 2020 09:46
-
-
Save iley/805fbfb6772c7b7ad3d084c59bdfef80 to your computer and use it in GitHub Desktop.
Script to switch AWS between profiles configured with SSO
This file contains 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 | |
set -e | |
new_profile="$1" | |
if [[ -z "$new_profile" ]]; then | |
# Just list existing profiles. | |
profiles=$(cat ~/.aws/config | perl -ne 'print if s/\[profile\s+(\S+)\]/$1/') | |
default_account=$(aws configure get sso_account_id --profile default) | |
for profile in $profiles; do | |
profile_account=$(aws configure get sso_account_id --profile $profile) | |
if [[ $default_account == $profile_account ]]; then | |
echo " * $profile" | |
else | |
echo " $profile" | |
fi | |
done | |
else | |
profile_account=$(aws configure get sso_account_id --profile $new_profile) | |
aws --profile default configure set sso_account_id $profile_account | |
echo "Default profile is set to $new_profile" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment