pythonamazon-cognito

how to get list of users based on created date/updated date from cognito


I am trying to fetch users from Cognito with sub and created date, able to fetch the user using sub but it's not accepting for created date, as this is not attribute to pass for filter. Below is the code for the same, i want to pass created in filter Filter="created ="2020-06-30""

 import boto3

 client = boto3.client('cognito-idp',region_name='us-east-2',
                     aws_access_key_id='XXXXXX',
                     aws_secret_access_key='XXXXXXX',
                     )

  response1 = client.list_users(UserPoolId='us-east-2_XXXXXX',AttributesToGet= 
  ['birthdate','name','sub'], Filter="sub =\"XXXXX-dCCa-4121-94c9-XXXXXX\"")

  print(response1)

error: InvalidParameterException: An error occurred (InvalidParameterException) when calling the ListUsers operation: Invalid search attribute: UserCreateDate


Solution

  • From the official AWS Docs:

    You can only search for the following standard attributes:

    • username (case-sensitive)

    • email

    • phone_number

    • name

    • given_name

    • family_name

    • preferred_username

    • cognito:user_status (called Status in the Console) (case-insensitive)

    • status (called Enabled in the Console) (case-sensitive)

    • sub

    You can write your own code to filter the results you get from list_users. Run a loop on the USERS value that is returned and create a new list with only users matching your filter criteria for date.