ListUsersCommand

Given a user pool ID, returns a list of users and their basic details in a user pool.

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

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CognitoIdentityProviderClient, ListUsersCommand } from "@aws-sdk/client-cognito-identity-provider"; // ES Modules import
// const { CognitoIdentityProviderClient, ListUsersCommand } = require("@aws-sdk/client-cognito-identity-provider"); // CommonJS import
const client = new CognitoIdentityProviderClient(config);
const input = { // ListUsersRequest
  UserPoolId: "STRING_VALUE", // required
  AttributesToGet: [ // SearchedAttributeNamesListType
    "STRING_VALUE",
  ],
  Limit: Number("int"),
  PaginationToken: "STRING_VALUE",
  Filter: "STRING_VALUE",
};
const command = new ListUsersCommand(input);
const response = await client.send(command);
// { // ListUsersResponse
//   Users: [ // UsersListType
//     { // UserType
//       Username: "STRING_VALUE",
//       Attributes: [ // AttributeListType
//         { // AttributeType
//           Name: "STRING_VALUE", // required
//           Value: "STRING_VALUE",
//         },
//       ],
//       UserCreateDate: new Date("TIMESTAMP"),
//       UserLastModifiedDate: new Date("TIMESTAMP"),
//       Enabled: true || false,
//       UserStatus: "UNCONFIRMED" || "CONFIRMED" || "ARCHIVED" || "COMPROMISED" || "UNKNOWN" || "RESET_REQUIRED" || "FORCE_CHANGE_PASSWORD" || "EXTERNAL_PROVIDER",
//       MFAOptions: [ // MFAOptionListType
//         { // MFAOptionType
//           DeliveryMedium: "SMS" || "EMAIL",
//           AttributeName: "STRING_VALUE",
//         },
//       ],
//     },
//   ],
//   PaginationToken: "STRING_VALUE",
// };

Example Usage

 Loading code editorLoading code editor

ListUsersCommand Input

See ListUsersCommandInput for more details

Parameter
Type
Description
UserPoolId
Required
string | undefined

The ID of the user pool where you want to display or search for users.

AttributesToGet
string[] | undefined

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 an AttributesToGet parameter, Amazon Cognito returns all attributes for each user.

Use AttributesToGet with required attributes in your user pool, or in conjunction with Filter. 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 an AttributesToGet parameter returns results.

Filter
string | undefined

A filter string of the form "AttributeName Filter-Type "AttributeValue". Quotation marks within the filter string must be escaped using the backslash ("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, ListUsers returns 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 --query parameter of the list-users action 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.

Limit
number | undefined

The maximum number of users that you want Amazon Cognito to return in the response.

PaginationToken
string | undefined

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.

ListUsersCommand Output

See ListUsersCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
PaginationToken
string | undefined

The identifier that Amazon Cognito returned with the previous request to this operation. When you include a pagination token in your request, Amazon Cognito returns the next set of items in the list. By use of this token, you can paginate through the full list of items.

Users
UserType[] | undefined

An array of user pool users who match your query, and their attributes.

Throws

Name
Fault
Details
InternalErrorException
server

This exception is thrown when Amazon Cognito encounters an internal error.

InvalidParameterException
client

This exception is thrown when the Amazon Cognito service encounters an invalid parameter.

NotAuthorizedException
client

This exception is thrown when a user isn't authorized.

ResourceNotFoundException
client

This exception is thrown when the Amazon Cognito service can't find the requested resource.

TooManyRequestsException
client

This exception is thrown when the user has made too many requests for a given operation.

CognitoIdentityProviderServiceException
Base exception class for all service exceptions from CognitoIdentityProvider service.