Skip to content

Instantly share code, notes, and snippets.

@bzcorn
Last active February 26, 2019 19:47
Show Gist options
  • Save bzcorn/74d0000038bce5dbfa152e9b7e4f536f to your computer and use it in GitHub Desktop.
Save bzcorn/74d0000038bce5dbfa152e9b7e4f536f to your computer and use it in GitHub Desktop.
This script will take the output of an aws sts assume-role and automatically export it into your Env Vars.
import sys
import json
def main(PIPED_IN):
"""
"""
a = json.loads(PIPED_IN)
env_var_values = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
sts_values = ["AccessKeyId", "SecretAccessKey", "SessionToken"]
for key,value in zip(env_var_values, sts_values):
print(f"export {key}={a['Credentials'][value]}")
return
if __name__ == "__main__":
PIPED_IN = ""
for line in sys.stdin:
PIPED_IN += line
main(PIPED_IN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment