Skip to content

Instantly share code, notes, and snippets.

@techsolx
Last active January 6, 2021 20:02
Show Gist options
  • Save techsolx/3a685137190b2af4c8b7860084cbf4b5 to your computer and use it in GitHub Desktop.
Save techsolx/3a685137190b2af4c8b7860084cbf4b5 to your computer and use it in GitHub Desktop.
Bash function to export aws credentials into environment

Using aws named profiles allow export using a bash function:

# Allow user to set aws profile in env
# requires aws and jq
# assume working role
awr() {
   if [ -x "$(command -v jq)" ] && [ -x "$(command -v aws)" ]; then
       export AWS_PROFILE=$1
       echo -n "Assumed working role: "
       aws sts get-caller-identity | jq .Arn
   fi
   }

then assuming you have a user-1 named profile in your ~/.aws/config file, export that user into the environment with:

awr user-1

Function then calls aws sts get-caller-identity to confirm what aws users is loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment