list_users
¶
list_users(
user_pool_id: UserPoolIdType,
*,
config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
attributes_to_get: Optional[SearchedAttributeNamesListType] = None,
limit: Optional[QueryLimitType] = None,
pagination_token: Optional[SearchPaginationTokenType] = None,
filter: Optional[UserFilterType] = None,
) -> ListUsersResponse
Given a user pool ID, returns a list of users and their basic details in a user pool.
This operation is eventually consistent. You might experience a delay before results are up-to-date. To validate the existence or configuration of an individual user, use AdminGetUser.
Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.
Learn more
Parameters:
-
user_pool_id(UserPoolIdType) –The ID of the user pool where you want to display or search for users.
-
attributes_to_get(Optional[SearchedAttributeNamesListType], default:None) –A JSON array of user attribute names, for example
given_name, that you want Amazon Cognito to include in the response for each user. When you don't provide anAttributesToGetparameter, Amazon Cognito returns all attributes for each user.Use
AttributesToGetwith required attributes in your user pool, or in conjunction withFilter. Amazon Cognito returns an error if not all users in the results have set a value for the attribute you request. Attributes that you can't filter on, including custom attributes, must have a value set in every user profile before anAttributesToGetparameter returns results. -
limit(Optional[QueryLimitType], default:None) –The maximum number of users that you want Amazon Cognito to return in the response. In some SDK contexts, this operation might return fewer items than you specify in the
Limitparameter without having reached the end of the full list. If the response contains aPaginationToken, then there are more results. -
pagination_token(Optional[SearchPaginationTokenType], default:None) –This API operation returns a limited number of results. The pagination token is an identifier that you can present in an additional API request with the same parameters. When you include the pagination token, Amazon Cognito returns the next set of items after the current list. Subsequent requests return a new pagination token. By use of this token, you can paginate through the full list of items.
-
filter(Optional[UserFilterType], default:None) –A filter string of the form
"AttributeName Filter-Type "AttributeValue". Quotation marks within the filter string must be escaped using the backslash (\) character. For example,"family_name = \"Reddy\"".-
AttributeName: The name of the attribute to search for. You can only search for one attribute at a time.
-
Filter-Type: For an exact match, use
=, for example, "given_name = \"Jon\"". For a prefix ("starts with") match, use^=, for example, "given_name ^= \"Jon\"". -
AttributeValue: The attribute value that must be matched for each user.
If the filter string is empty,
ListUsersreturns all users in the user pool.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
Custom attributes aren't searchable.
You can also list users with a client-side filter. The server-side filter matches no more than one attribute. For an advanced search, use a client-side filter with the
--queryparameter of thelist-usersaction in the CLI. When you use a client-side filter, ListUsers returns a paginated list of zero or more users. You can receive multiple pages in a row with zero results. Repeat the query with each pagination token that is returned until you receive a null pagination token value, and then review the combined result.For more information about server-side and client-side filtering, see FilteringCLI output in the Command Line Interface User Guide.
For more information, see Searching for Users Using the ListUsers API and Examples of Using the ListUsers API in the Amazon Cognito Developer Guide.
-
Raises:
-
InternalErrorException–This exception is thrown when Amazon Cognito encounters an internal error.
-
InvalidParameterException–This exception is thrown when the Amazon Cognito service encounters an invalid parameter.
-
NotAuthorizedException–This exception is thrown when a user isn't authorized.
-
OperationNotEnabledException–This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.
-
ResourceNotFoundException–This exception is thrown when the Amazon Cognito service can't find the requested resource.
-
TooManyRequestsException–This exception is thrown when the user has made too many requests for a given operation.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
A ListUsers request for the next 3 users whose email address starts with "testuser." This request submits a value for all possible parameters for ListUsers. By iterating the PaginationToken, you can page through and collect all users in a user pool.
>>> client.list_users(attributes_to_get=['email', 'sub'], filter='"email"^="testuser"', limit=3, pagination_token='abcd1234EXAMPLE', user_pool_id='us-east-1_EXAMPLE')
Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 | |