Last active
November 6, 2022 15:14
-
-
Save azrsh/b8c3ff4907f6e2704cd2b7b9d611f57c to your computer and use it in GitHub Desktop.
assume role + envchain
This file contains 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
#!/bin/bash | |
set -euo pipefail | |
function main() { | |
local -r name=$1 | |
local -r arn=$2 | |
local out | |
out=$(aws sts assume-role --role-arn "$arn" --role-session-name "$USER-$(date +'%s')") | |
jq -r .Credentials.AccessKeyId <<< "$out" | envchain --set "$name" AWS_ACCESS_KEY_ID | |
echo | |
jq -r .Credentials.SecretAccessKey <<< "$out" | envchain --set $name AWS_SECRET_ACCESS_KEY | |
echo | |
jq -r .Credentials.SessionToken <<< "$out" | envchain --set $name AWS_SESSION_TOKEN | |
echo | |
1>&2 echo -n "exipires at " | |
1>&2 jq -r .Credentials.Expiration <<< "$out" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment