Skip to content

Instantly share code, notes, and snippets.

@rakodev
Last active June 8, 2022 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakodev/10fc13b35073e4193119b9c0cb4ba4a4 to your computer and use it in GitHub Desktop.
Save rakodev/10fc13b35073e4193119b9c0cb4ba4a4 to your computer and use it in GitHub Desktop.
Export AWS credentials from AWS SSO
#!/bin/bash
# use another role-name if needed
role_credentials=$(aws sso get-role-credentials --role-name=AdministratorAccess --account-id=$(aws sts get-caller-identity --query "Account" --output text) --access-token=$(jq .accessToken ~/.aws/sso/cache/$(ls -1rt ~/.aws/sso/cache | tail -n1) | sed -r 's/^"|"$//g') | jq -r '.roleCredentials')
export AWS_ACCESS_KEY_ID="$(echo $role_credentials | jq -r '.accessKeyId')"
export AWS_SECRET_ACCESS_KEY="$(echo $role_credentials | jq -r '.secretAccessKey')"
export AWS_SESSION_TOKEN="$(echo $role_credentials | jq -r '.sessionToken')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment