-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathcheck_iam_key.py
More file actions
27 lines (23 loc) · 857 Bytes
/
check_iam_key.py
File metadata and controls
27 lines (23 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import boto3
from botocore.exceptions import ClientError
account1_client = boto3.client( 'iam',
aws_access_key_id="",
aws_secret_access_key=""
)
account2_client = boto3.client( 'iam',
aws_access_key_id="",
aws_secret_access_key=""
)
access_keys=[]
for access_key in access_keys:
try:
response = account1_client.get_access_key_last_used(AccessKeyId=access_key)
except ClientError as e:
try:
response = account2_client.get_access_key_last_used(AccessKeyId=access_key)
except ClientError as e:
print("Access key %s not found in the given AWS accounts." % (access_key))
else:
print( "Access_key %s found in account2"% (access_key))
else:
print( "Access_key %s found in account1"% (access_key))