The documentation says that you can get the user as follows:
response = client.list_users(
UserPoolId='string',
AttributesToGet=[
'string',
],
Limit=123,
PaginationToken='string',
Filter='string'
)
from:https://boto3.readthedocs.io/en/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.list_users
import boto3
client = boto3.client('cognito-idp')
response = client.list_users(
UserPoolId='YOUR_USER_POOL_ID'
)
If you specify only the user pool ID, the first 60 all users </ s> will be returned.
I thought that "If you do not specify Limit, you will get all the cases", but it seems that only the first 60 cases are acquired.
By writing ʻemail =" hoge "` in Filter, you can search only users with the corresponding email address.
import boto3
client = boto3.client('cognito-idp')
response = client.list_users(
UserPoolId='YOUR_USER_POOL_ID',
Filter="email = \"hide\"",
)
In this example, we will get all users who use email addresses that contain the characters hide
.
By setting ^ =
instead of =
, you can also search for "email addresses starting with hide".
Filter
You can only search for standard attributes. Custom attributes cannot be searched. This is because only indexed attributes can be searched, and custom attributes cannot be indexed. http://docs.aws.amazon.com/ja_jp/cognito/latest/developerguide/how-to-manage-user-accounts.html#cognito-user-pools-searching-for-users-using-listusers-api
It seems that user search using custom attributes is not currently supported.
It seems better to store the attributes you want to search in DynamoDB or AES (Amazon Elasticsearch Service).
You can narrow down the number of acquisitions by specifying a number in the Limit
query.
import boto3
client = boto3.client('cognito-idp')
response = client.list_users(
UserPoolId='YOUR_USER_POOL_ID',
Limit=10,
)
If you try to acquire 61 or more data at once and set Limit to a value of 61 or more, an error will occur.
ClientError: An error occurred (InvalidParameterException) when calling the ListUsers operation: 1 validation error detected: Value '500' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 60
I think it would be better to make a recursive call like the following.
def getUser():
client = boto3.client('cognito-idp')
response = self.client.list_users(
UserPoolId="YOUR_USERPOOL_ID"
)
return response
def getUsersWithPagenation(PaginationToken):
response = self.client.list_users(
UserPoolId="YOUR_USERPOOL_ID",
PaginationToken=PaginationToken
)
return response
def workerNode(users):
for user in users["Users"]:
# Do Something
if 'PaginationToken' in users:
newUsers = getUsersWithPagenation(users["PaginationToken"])
workerNode(newUsers)
users = getUser()
workerNode(users)
Recommended Posts