Skip to content

Instantly share code, notes, and snippets.

@autch
Created September 14, 2020 01:44
Show Gist options
  • Save autch/e68e2fd54e953640a83e93f65fa919e4 to your computer and use it in GitHub Desktop.
Save autch/e68e2fd54e953640a83e93f65fa919e4 to your computer and use it in GitHub Desktop.
show AWS credentials from standard configuration
#!/usr/bin/env python
import boto3
session = boto3.Session()
cred = session.get_credentials().get_frozen_credentials()
env = {
'AWS_PROFILE': session.profile_name,
'AWS_DEFAULT_REGION': session.region_name,
'AWS_ACCESS_KEY_ID': cred.access_key,
'AWS_SECRET_ACCESS_KEY': cred.secret_key,
'AWS_SESSION_TOKEN': cred.token
}
for k, v in [(k, v) for k, v in env.items() if v is not None]:
print("export {key}=\"{value}\"".format(key=k, value=v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment