Skip to content

Instantly share code, notes, and snippets.

@jcaxmacher
Created August 4, 2019 11:00
Show Gist options
  • Save jcaxmacher/1701c7e6e23d05f7d3023dd940304cce to your computer and use it in GitHub Desktop.
Save jcaxmacher/1701c7e6e23d05f7d3023dd940304cce to your computer and use it in GitHub Desktop.
Get AWS Assumed-Role Credentials in a Windows-Environment-Variable-friendly format
REM %1 - AWS credential profile for the AssumRole API call
REM %2 - The ARN of the role to assume
REM %3 - The name of the newly created role session
aws --profile %1 sts assume-role --role-arn %2 --role-session-name %3 | python -c "import sys,json;data=sys.stdin.read();creds=json.loads(data);print(f'set AWS_ACCESS_KEY_ID={creds[""Credentials""][""AccessKeyId""]}');print(f'set AWS_SECRET_ACCESS_KEY={creds[""Credentials""][""SecretAccessKey""]}');print(f'set AWS_SESSION_TOKEN={creds[""Credentials""][""SessionToken""]}')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment