Skip to content

Instantly share code, notes, and snippets.

@simbo1905
Last active January 15, 2026 15:08
Show Gist options
  • Select an option

  • Save simbo1905/46de577a290b99d2bf9d9501c2d305e3 to your computer and use it in GitHub Desktop.

Select an option

Save simbo1905/46de577a290b99d2bf9d9501c2d305e3 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
usage() {
cat <<'EOF'
aws_sso_env.sh - Print AWS env exports from an SSO profile
Usage:
bin/aws_sso_env.sh <profile>
Examples:
aws sso login --profile DataSandbox
eval "$(bin/aws_sso_env.sh DataSandbox)"
aws sts get-caller-identity
Notes:
- Prints shell 'export KEY=VALUE' lines to stdout.
- Requires AWS CLI v2.
EOF
}
case "${1-}" in
-h|--help)
usage
exit 0
;;
'')
usage >&2
exit 2
;;
esac
if [ "$#" -ne 1 ]; then
usage >&2
exit 2
fi
profile=$1
aws configure export-credentials --profile "$profile" --format env-no-export \
| while IFS= read -r line; do
case $line in
'' )
continue
;;
esac
key=${line%%=*}
value=${line#*=}
escaped=$(printf %s "$value" | sed "s/'/'\\\\''/g")
printf "export %s='%s'\n" "$key" "$escaped"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment