Skip to content

Instantly share code, notes, and snippets.

@thoroc
Created April 4, 2025 14:33
Show Gist options
  • Save thoroc/dbb094c0f7511f4b17a559c06205ac8e to your computer and use it in GitHub Desktop.
Save thoroc/dbb094c0f7511f4b17a559c06205ac8e to your computer and use it in GitHub Desktop.
Shell function to select an AWS profile when using Leapp
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