Skip to content

Instantly share code, notes, and snippets.

@azrsh
Last active November 6, 2022 15:14
Show Gist options
  • Save azrsh/b8c3ff4907f6e2704cd2b7b9d611f57c to your computer and use it in GitHub Desktop.
Save azrsh/b8c3ff4907f6e2704cd2b7b9d611f57c to your computer and use it in GitHub Desktop.
assume role + envchain
#!/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