Last active
June 8, 2022 09:59
-
-
Save rakodev/10fc13b35073e4193119b9c0cb4ba4a4 to your computer and use it in GitHub Desktop.
Export AWS credentials from AWS SSO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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