Created
September 12, 2018 18:15
-
-
Save jg75/ee761137a752166d29204cd99f3946ed to your computer and use it in GitHub Desktop.
Just some stuff to remember
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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