Created
April 4, 2025 14:33
-
-
Save thoroc/dbb094c0f7511f4b17a559c06205ac8e to your computer and use it in GitHub Desktop.
Shell function to select an AWS profile when using Leapp
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
select_aws_profile () { | |
local profiles=($(leapp session list --output=json | jq -r '[.[] | select(.status=="active")] | .[].profileId')) | |
if [[ ${#profiles[@]} -eq 0 ]] | |
then | |
unset AWS_PROFILE | |
echo "AWS_PROFILE unset as there are no profiles" | |
elif [[ ${#profiles[@]} -eq 1 ]] | |
then | |
export AWS_PROFILE="${profiles}" | |
echo "AWS_PROFILE set to ${profiles}" | |
else | |
leapp session list --output=json | jq -r '[.[] | select(.status=="active")] | (.[0] | keys_unsorted | @tsv), (.[] |map(.) |@tsv)' | column -ts $'\t' | |
select profile in "${profiles[@]}" | |
do | |
if [[ -n $profile ]] | |
then | |
export AWS_PROFILE=$profile | |
echo "AWS_PROFILE set to $profile" | |
break | |
else | |
echo "Invalid selection" | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment