Skip to content

Instantly share code, notes, and snippets.

@saudkhanzada
Created May 28, 2024 12:59
Show Gist options
  • Save saudkhanzada/4e336d49c84f931381ac65738c94a845 to your computer and use it in GitHub Desktop.
Save saudkhanzada/4e336d49c84f931381ac65738c94a845 to your computer and use it in GitHub Desktop.
Getting AWS credentials using AWS SSO
# Add the following to your .zshrc or .bashrc
sso() {
local profile_name="$1"
# Check if the profile exists by attempting to get a known setting
if ! aws configure get sso_account_id --profile "$profile_name" &>/dev/null; then
echo "Profile '$profile_name' does not exist. Configuring AWS SSO profile..."
aws configure sso --profile "$profile_name"
fi
# Export credentials
eval "$(aws configure export-credentials --format env --profile "$profile_name")"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment