Created
August 10, 2016 09:38
-
-
Save knakayama/63254d035f0cb1dcef91b117039da057 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -x | |
role_session_name="$USER" | |
duration_seconds=3600 # 900-3600 | |
assume_role_arn="arn:aws:iam::<account-id>:role/<role-name>" | |
account_id="$(aws ec2 describe-security-groups | jq -r '.SecurityGroups[0].OwnerId')" | |
result="$(aws sts assume-role --role-arn $assume_role_arn --role-session-name $role_session_name --duration-seconds $duration_seconds)" | |
access_key_id="$(echo $result | jq -r '.Credentials.AccessKeyId')" | |
secret_access_key="$(echo $result | jq -r '.Credentials.SecretAccessKey')" | |
session_token="$(echo $result | jq -r '.Credentials.SessionToken')" | |
export AWS_ACCESS_KEY_ID="$access_key_id" | |
export AWS_SECRET_ACCESS_KEY="$secret_access_key" | |
export AWS_SESSION_TOKEN="$session_token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment