Skip to content

Instantly share code, notes, and snippets.

@kamataryo
Created June 28, 2022 23:03
Show Gist options
  • Save kamataryo/b9fb9c8b8444e7b53da5d93ecf8678a1 to your computer and use it in GitHub Desktop.
Save kamataryo/b9fb9c8b8444e7b53da5d93ecf8678a1 to your computer and use it in GitHub Desktop.
list Amazon Cognito idp users with boto3
import boto3
client = boto3.client('cognito-idp', region_name='ap-northeast-1')
userpool_id = 'ap-northeast-1_aaaaaaaa'
users = []
response = client.list_users(
UserPoolId = userpool_id
)
users.extend(response['Users'])
while 'PaginationToken' in response:
response = client.list_users(
UserPoolId = userpool_id,
PaginationToken = response['PaginationToken']
)
users.extend(response['Users'])
for user in users:
userAttrbutes = user['Attributes']
for userAttribute in userAttrbutes:
name = userAttribute['Name']
value = userAttribute['Value']
user[name] = value
del user['Attributes']
rows = []
result = {
"columns": [
{ "name": "Username", "type": "string" },
{ "name": "UserCreateDate", "type": "string" },
{ "name": "UserLastModifiedDate", "type": "string" },
{ "name": "Enabled", "type": "boolean" },
{ "name": "UserStatus", "type": "string" },
# user attributes
{ "name": "sub", "type": "string" },
{ "name": "email_verified", "type": "string" },
{ "name": "email", "type": "string" },
],
"rows": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment