-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers90daysdel.py
More file actions
executable file
·33 lines (28 loc) · 1.13 KB
/
users90daysdel.py
File metadata and controls
executable file
·33 lines (28 loc) · 1.13 KB
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
28
29
30
31
32
33
import datetime
import pytz
import dateutil
from dateutil import parser
from dateutil.tz import tzutc
import boto3
conn = boto3.client('iam')
timeLimit=datetime.datetime.now(tzutc()) - datetime.timedelta(days=90)
print "---------------------------------------------"
print "Username" + "\t\t" + "PasswordLastUsed"
print "---------------------------------------------"
paginator = conn.get_paginator('list_users')
for page in paginator.paginate():
for user in page['Users']:
if 'PasswordLastUsed' in user:
if user['PasswordLastUsed'] <= timeLimit:
name = user['UserName']
print user['UserName'], "\t\t" , user['PasswordLastUsed']
try:
response = conn.get_login_profile(UserName=name)
except Exception, e:
if e.response['ResponseMetadata']['HTTPStatusCode'] == 404:
print('User {} has no login profile'.format(name))
else:
response = conn.delete_login_profile(
UserName = name,
)
print "password deleted"