Skip to content

Commit 3c9ff8a

Browse files
authored
Create get_accountid.py
1 parent 9a849cf commit 3c9ff8a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

get_accountid.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import boto3
2+
import sys
3+
4+
# Script gets the AWS profile name as input param and
5+
# prints the corresponding account-id associated with the profile
6+
session = boto3.Session(profile_name=sys.argv[1])
7+
credentials = session.get_credentials()
8+
9+
# credentials = credentials.get_frozen_credentials()
10+
ACCESS_KEY = credentials.access_key
11+
SECRET_KEY = credentials.secret_key
12+
13+
client = boto3.client("sts", aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
14+
account_id = client.get_caller_identity()["Account"]
15+
print(account_id)

0 commit comments

Comments
 (0)