Skip to content

Instantly share code, notes, and snippets.

@bortels
Created January 22, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bortels/8556ed6c670dcae81890d045cbe84c9b to your computer and use it in GitHub Desktop.
Save bortels/8556ed6c670dcae81890d045cbe84c9b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# export the AWS environment for a given profile
import boto3
import argparse
parser = argparse.ArgumentParser(prog="exportaws",
description="Extract AWS credentials for a profile as env variables.")
parser.add_argument("profile", help="profile name in ~/.aws/config.")
args = parser.parse_args()
creds = boto3.session.Session(profile_name=args.profile).get_credentials()
print(f'export AWS_ACCESS_KEY={creds.access_key}')
print(f'export AWS_SECRET_ACCESS_KEY={creds.secret_key}')
print(f'export AWS_SESSION_TOKEN={creds.token}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment