Skip to content

Instantly share code, notes, and snippets.

@axelabs
Last active July 28, 2023 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelabs/5918ed31676fe92f844dd11283062317 to your computer and use it in GitHub Desktop.
Save axelabs/5918ed31676fe92f844dd11283062317 to your computer and use it in GitHub Desktop.
Export selected AWS profile into environments 🐚
# Usage from POSIX shell: . ./expAws.sh
PROFILES=$(awk configure list-profiles)
select PROFILE in $PROFILES; do
export AWS_ACCESS_KEY_ID="$(aws configure get aws_access_key_id --profile $PROFILE)"
export AWS_SECRET_ACCESS_KEY="$(aws configure get aws_secret_access_key --profile $PROFILE)"
export AWS_DEFAULT_REGION="$(aws configure get region --profile $PROFILE)"
export AWS_SESSION_TOKEN="$(aws configure get aws_session_token --profile $PROFILE)"
export AWS_SECURITY_TOKEN="$(aws configure get aws_security_token --profile $PROFILE)"
break
done
echo AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
echo AWS_SECRET_ACCESS_KEY=$(echo $AWS_SECRET_ACCESS_KEY|tr '[:print:]' '*')
echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION
if [[ $AWS_SESSION_TOKEN ]] && [[ $AWS_SECURITY_TOKEN ]]; then
echo "AWS_*_TOKENS loaded"
else
unset AWS_SESSION_TOKEN AWS_SECURITY_TOKEN
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment