Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaingray/5da2972082812048e78b06d0845109f0 to your computer and use it in GitHub Desktop.
Save iaingray/5da2972082812048e78b06d0845109f0 to your computer and use it in GitHub Desktop.
ListsTheUsersInTheAmazonCognitoUserPool
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