Forked from hawkerfun/ListsTheUsersInTheAmazonCognitoUserPool.py
Created
July 5, 2022 13:48
-
-
Save iaingray/5da2972082812048e78b06d0845109f0 to your computer and use it in GitHub Desktop.
ListsTheUsersInTheAmazonCognitoUserPool
This file contains 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
import boto3 | |
import datetime | |
# Amazon Cognito User Pool Configs | |
LIMIT = 60 | |
REGION = 'us-east-1' | |
USER_POOL_ID = 'us-east-1_aaaaaaaaa' | |
# Create boto3 CognitoIdentityProvider client | |
client = boto3.client('cognito-idp', REGION) | |
pagination_token = "" | |
# Degfine function that utilize ListUsers AWS API call | |
def get_list_cognito_users(cognito_idp_client, next_pagination_token ='', Limit = LIMIT): | |
return cognito_idp_client.list_users( | |
UserPoolId = USER_POOL_ID, | |
#AttributesToGet = ['name'], | |
Limit = Limit, | |
PaginationToken = next_pagination_token | |
) if next_pagination_token else cognito_idp_client.list_users( | |
UserPoolId = USER_POOL_ID, | |
#AttributesToGet = ['name'], | |
Limit = Limit | |
) | |
# Pull Batch of Amazon Cognito User Pool records | |
user_records = get_list_cognito_users( | |
cognito_idp_cliend = client, | |
next_pagination_token = pagination_token, | |
Limit = LIMIT | |
# Print out result | |
def datetimeconverter(o): | |
if isinstance(o, datetime.datetime): | |
return str(o) | |
json_formatted_str = json.dumps(user_records, indent=4, default=datetimeconverter) | |
print(json_formatted_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment