Skip to content

Instantly share code, notes, and snippets.

@tkazusa
Created October 20, 2019 15:03
Show Gist options
  • Save tkazusa/e6a59a7e07f279410e94d1be879a0ee2 to your computer and use it in GitHub Desktop.
Save tkazusa/e6a59a7e07f279410e94d1be879a0ee2 to your computer and use it in GitHub Desktop.
import boto3
sts_client = boto3.client("sts")
session = boto3.session.Session()
account_id = sts_client.get_caller_identity()["Account"]
region = session.region_name
credentials = session.get_credentials()
credentials = credentials.get_frozen_credentials()
with open('vars.env', 'w') as f:
f.write("AWS_ACCOUNT_ID=%s\n" % account_id)
f.write("AWS_DEFAULT_REGION=%s\n" % region)
f.write("AWS_ACCESS_KEY_ID=%s\n" % credentials.access_key)
f.write("AWS_SECRET_ACCESS_KEY=%s\n" % credentials.secret_key)
f.write("AWS_SESSION_TOKEN=%s\n" % credentials.token )
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment