Skip to content

Instantly share code, notes, and snippets.

@ctgardner
Created March 25, 2019 23:17
Show Gist options
  • Save ctgardner/340fcd2184e1dbc5c763c9d86c07745f to your computer and use it in GitHub Desktop.
Save ctgardner/340fcd2184e1dbc5c763c9d86c07745f to your computer and use it in GitHub Desktop.
Export AWS credentials of a role assumed via STS
#!/bin/bash
# usage: $ `aws sts assume-role --role-arn <arn> --role-session-name <session-name> | ./export_assumed_role.sh`
cat $1 | jq '.Credentials' | jq -r '.AccessKeyId, .SecretAccessKey, .SessionToken' | {
read -r access_key;
read -r secret_key;
read -r session_token;
echo "export AWS_ACCESS_KEY_ID=$access_key";
echo "export AWS_SECRET_ACCESS_KEY=$secret_key";
echo "export AWS_SESSION_TOKEN=$session_token";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment