Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Amazon Cognito says the user pool client does not exist

ErrorResourceNotFoundException: User pool client 1example23456789 does not exist.

Short answer

Cognito looks the app client ID up inside the Region you call. ResourceNotFoundException means that lookup found nothing. Either the ID is not an app client of that pool, the client was deleted, or your SDK calls a different Region than the one holding the pool. List the pool's clients in the right Region and compare the IDs.

  • Applies to Amazon Cognito user pools, AWS CLI 2.x, AWS SDK for JavaScript v3, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the app clients of the user pool, in the Region where the pool lives (pool IDs look like us-west-2_EXAMPLE). Then compare the ClientId values with the ID in your error.

    aws cognito-idp list-user-pool-clients --user-pool-id us-west-2_EXAMPLE --region us-west-2
  2. 2Match what you see, then jump to its fix

    1. 1The ID in the error is missing from the list-user-pool-clients output, but the pool shows other clients.The client ID belongs to another app client, pool or environmentFix
    2. 2The ID matches your config, but it is not in the list, and someone recently rebuilt the pool or cleaned up clients.The app client was deletedFix
    3. 3The client is visible in the console or CLI in one Region, but the app's requests go to a cognito-idp endpoint of another Region.The app calls a different Region than the one holding the poolFix

What does the error look like?

  • ResourceNotFoundException: User pool client 1example23456789 does not exist.
  • ResourceNotFoundException (HTTP status code 400) returned by InitiateAuth

Cause 1 of 3

The client ID belongs to another app client, pool or environment

1Check

Each app client has its own ID, and it belongs to exactly one user pool. A typo, an ID copied from a staging or test pool, or the ID of a second app in the same pool all give this error. The list output shows ClientId, ClientName and UserPoolId for every client.

aws cognito-idp describe-user-pool-client \
  --user-pool-id us-west-2_EXAMPLE \
  --client-id 1example23456789 \
  --region us-west-2

2Fix

Copy the ClientId of the client your app should use from the list output into the app's configuration and redeploy the app. Check that the user pool ID in the same config matches the pool you listed.

# .env of the app (names are yours; the values come from the list output)
COGNITO_USER_POOL_ID=us-west-2_EXAMPLE
COGNITO_CLIENT_ID=1example23456789

3Verify

describe-user-pool-client returns the details of that client. Then repeat the sign-in that failed.

aws cognito-idp describe-user-pool-client --user-pool-id us-west-2_EXAMPLE --client-id 1example23456789 --region us-west-2

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 3

The app client was deleted

1Check

Deleting an app client blocks every app that still uses its ID. A config that still holds the old ID keeps failing until you point it at a client that exists.

aws cognito-idp list-user-pool-clients --user-pool-id us-west-2_EXAMPLE --region us-west-2

2Fix

Use the ID of the replacement client if one exists. If none exists, create a new app client and put its ID into the app. A client's secret setting cannot be changed after creation, so create the new client with a secret only if the app sends SECRET_HASH.

aws cognito-idp create-user-pool-client --user-pool-id us-west-2_EXAMPLE --client-name my-web-app --region us-west-2

3Verify

The new ClientId appears in the list, and the sign-in works with it.

aws cognito-idp list-user-pool-clients --user-pool-id us-west-2_EXAMPLE --region us-west-2

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 3 of 3

The app calls a different Region than the one holding the pool

1Check

User pools are created per Region, and each Region has its own endpoint (cognito-idp.us-west-2.amazonaws.com for us-west-2). The SDK for JavaScript does not pick a Region by itself, so a missing or wrong AWS_REGION, or a region value copied from another environment, sends the call to a Region that does not hold the client.

echo "AWS_REGION=$AWS_REGION"
grep -rn "region" src/ .env* 2>/dev/null

2Fix

Set the Region of the pool for the Cognito client: in the client constructor option region, in the AWS_REGION environment variable, or in the shared config file. A Region passed to the constructor wins over the other two.

export AWS_REGION=us-west-2
node server.js

3Verify

Run the failing call again. The same ClientId that was rejected now returns the client or signs the user in.

aws cognito-idp describe-user-pool-client --user-pool-id us-west-2_EXAMPLE --client-id 1example23456789 --region us-west-2

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Keep the user pool ID, the app client ID and the Region together in one config block per environment, so they cannot be mixed between staging and production.
  • Read the app client ID from the pool (list-user-pool-clients) in your deploy script instead of pasting it by hand.
  • Before deleting an app client, search every app and config for its ID.
  • Set the Region explicitly in the client constructor instead of relying on the machine's environment.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Security

Amazon Cognito /oauth2/token returns unauthorized_client

{"error":"unauthorized_client","error_description":"invalid_redirect"}

Cognito returns unauthorized_client from /oauth2/token when the app client is not allowed to use the grant you asked for, or when the redirect_uri in the token request differs from the one used at /oauth2/authorize.

3 causes, each with a fix

Back end

The AWS SDK in Node.js cannot find any credentials

Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.