Skip to content

Instantly share code, notes, and snippets.

@jg75
Created September 12, 2018 18:15
Show Gist options
  • Save jg75/ee761137a752166d29204cd99f3946ed to your computer and use it in GitHub Desktop.
Save jg75/ee761137a752166d29204cd99f3946ed to your computer and use it in GitHub Desktop.
Just some stuff to remember
"""Some boto3 user stuff."""
import boto3
def get_account_id(session):
"""Get the account id for the current session."""
sts_client = session.client("sts")
identity = sts_client.get_caller_identity()
return identity["Account"]
def print_user_stuff(session):
"""Print some user stuff."""
iam = session.resource("iam")
current_user = iam.CurrentUser()
print(current_user.user_name)
print(current_user.arn)
print(session.region_name)
print(get_account_id(session))
if __name__ == "__main__":
session = boto3.session.Session()
print_user_stuff(session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment