Created
September 18, 2025 23:34
-
-
Save adenot/0db332ebc911c721698b7eec14d18709 to your computer and use it in GitHub Desktop.
usage: source assume-role.sh <arn>
This file contains hidden or 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 | |
| # Usage: source assume-role.sh <role-arn> <session-name> | |
| ROLE_ARN=${1:?Role ARN required} | |
| SESSION_NAME=${2:-"AssumeRoleSession"} | |
| CREDS=$(aws sts assume-role \ | |
| --role-arn "$ROLE_ARN" \ | |
| --role-session-name "$SESSION_NAME" \ | |
| --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \ | |
| --output text) | |
| export AWS_ACCESS_KEY_ID=$(echo $CREDS | awk '{print $1}') | |
| export AWS_SECRET_ACCESS_KEY=$(echo $CREDS | awk '{print $2}') | |
| export AWS_SESSION_TOKEN=$(echo $CREDS | awk '{print $3}') | |
| echo "✓ Assumed role: $ROLE_ARN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment