Skip to content

Instantly share code, notes, and snippets.

@dougneal
Created July 6, 2017 10:28
Show Gist options
  • Save dougneal/bcdebd8af05ddfec8beee5f3c1c35f93 to your computer and use it in GitHub Desktop.
Save dougneal/bcdebd8af05ddfec8beee5f3c1c35f93 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
arn="$1"
session="$2"
response="$(aws sts assume-role --role-arn "$arn" --role-session-name "$session")"
AWS_ACCESS_KEY_ID="$(echo "$response" | jq -r '.Credentials.AccessKeyId')"
AWS_SECRET_ACCESS_KEY="$(echo "$response" | jq -r '.Credentials.SecretAccessKey')"
AWS_SESSION_TOKEN="$(echo "$response" | jq -r '.Credentials.SessionToken')"
echo "export AWS_ACCESS_KEY_ID=\"${AWS_ACCESS_KEY_ID}\""
echo "export AWS_SECRET_ACCESS_KEY=\"${AWS_SECRET_ACCESS_KEY}\""
echo "export AWS_SESSION_TOKEN=\"${AWS_SESSION_TOKEN}\""
echo "Expiry: $(echo "$response" | jq -r '.Credentials.Expiration') Now: $(date)" > /dev/stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment