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
9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 | |