Skip to content

Instantly share code, notes, and snippets.

@toshke
Created April 20, 2021 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshke/2199fa984395784312dd1d43002238c2 to your computer and use it in GitHub Desktop.
Save toshke/2199fa984395784312dd1d43002238c2 to your computer and use it in GitHub Desktop.
assume-role
#!/bin/bash
set -eox pipefail
if [ "$1" == "" ]; then
echo "usage: assume-role arn [session-name=nikolatosic\$(date +%s)] [duration=900]"
exit 1
fi
if [ "$2" == "" ]; then
echo "usage: assume-role arn [session-name\$(date +%s)] [duration=900]"
session_name="nikolatosic$(date +%s)"
fi
if [ "$3" == "" ]; then
duration="900"
else
duration="$3"
fi
# KST=access*K*ey, *S*ecretkey, session*T*oken
result=$(aws sts assume-role --role-arn "$1" \
--role-session-name "$session_name" \
--duration-seconds "$duration" \
--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' \
--output text)
echo "export AWS_ACCESS_KEY_ID='${KST[0]}'"
echo "export AWS_SECRET_ACCESS_KEY='${KST[1]}'"
echo "export AWS_SESSION_TOKEN='${KST[2]}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment