-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_user.py
61 lines (48 loc) · 1.51 KB
/
export_user.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import logging
import boto3
from botocore.exceptions import ClientError
from time import sleep
import json
import csv
def main():
client = boto3.client('cognito-idp')
UserPool_Id = "us-east-1_xxxxxxxx"
userData = open('./UserData.csv', 'w')
csvwriter = csv.writer(userData)
csvwriter.writerow (['User Name', "Email"])
response = client.list_users(
UserPoolId=UserPool_Id
)
i = len(response["Users"])
pageToken = response["PaginationToken"]
for user in response["Users"]:
print (user["Username"])
userName = user["Username"]
email = ''
for attr in user["Attributes"]:
if "email" == attr["Name"]:
print attr["Value"]
email = attr["Value"]
break
csvwriter.writerow ([userName, email])
while i > 59:
sleep(0.05)
pageToken = response["PaginationToken"]
response = client.list_users(
UserPoolId=UserPool_Id,
PaginationToken=pageToken,
)
i = len(response["Users"])
for user in response["Users"]:
print (user["Username"])
userName = user["Username"]
email = ''
for attr in user["Attributes"]:
if "email" == attr["Name"]:
print (attr["Value"])
email = attr["Value"]
break
csvwriter.writerow ([userName, email])
userData.close()
if __name__ == '__main__':
main()