# with_role bc-videocloud-prod arn:aws:iam::749779118921:role/dev-admin
function with_role() {
>&2 echo "Generating Temporary Session Creds..."
CREDS=$(aws sts assume-role \
--profile $1 \
--role-arn $2 \
--role-session-name "${USER}-session" \
--query Credentials \
--output text)
echo ${=CREDS}
if [ -n "$ZSH_VERSION" ]; then
TEMP_EXPIRATION=$(echo ${=CREDS} | cut -d " " -f 2)
export AWS_ACCESS_KEY_ID=$(echo ${=CREDS} | cut -d " " -f 1)
export AWS_SECRET_ACCESS_KEY=$(echo ${=CREDS} | cut -d " " -f 3)
export AWS_SESSION_TOKEN=$(echo ${=CREDS} | cut -d " " -f 4)
else
TEMP_EXPIRATION=$(echo ${CREDS} | cut -d " " -f 2)
export AWS_ACCESS_KEY_ID=$(echo ${CREDS} | cut -d " " -f 1)
export AWS_SECRET_ACCESS_KEY=$(echo ${CREDS} | cut -d " " -f 3)
export AWS_SESSION_TOKEN=$(echo ${CREDS} | cut -d " " -f 4)
fi
>&2 echo "Generted Creds. Will Expire in 1 hour @ ${TEMP_EXPIRATION }"
${@:3}
}
Last active
July 21, 2021 01:17
-
-
Save charlires/848e7225c1dcb88a649c9adaebee413c to your computer and use it in GitHub Desktop.
Utils
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment