Skip to content

Cognito Search doesn’t return results when using prefix with special character (@) in some regions.

0

As you can see in the screenshot, search tool won't return users for email input ending with @, which may be useful, If we have a list of users like: julian@ark.com, julian-the-best@ark.com, julian-the-worst@ark.com We may want to just look for julian@ to exclude the rest.

This is happening in eu-west-1 region, but not in us-east-1, proving inconsistent.

Comparison search filter with and without special character

Region us-east-1 Enter image description here

asked a year ago356 views
1 Answer
-1

The issue you're experiencing with the Cognito ListUsersCommand Filter not returning results when using a prefix with the special character "@" is due to the way Amazon Cognito handles search queries, particularly for email attributes.

When searching for users in Amazon Cognito using the ListUsers API, the filter string for email addresses does not support prefix matching with special characters like "@". The prefix search (using ^=) is designed to work with the beginning of the attribute value, but it doesn't handle special characters in the middle of the string as you might expect.

For email searches, Cognito treats the entire email address as a single string. When you try to search for "julian@", it's looking for email addresses that start with exactly that string, including the "@" symbol, which is not how email addresses are typically structured.

To search for users with email addresses starting with "julian" and any domain, you would need to use the prefix search without including the "@" symbol:

email ^= "julian"

This will return all users whose email addresses start with "julian", regardless of what comes after it.

If you specifically need to filter for users with a certain domain, you would need to use an exact match instead of a prefix match. For example:

email = "julian@ark.com"

Unfortunately, there isn't a built-in way to do a partial match that includes special characters like "@" in the middle of the search string using the ListUsers API. If you need more complex search capabilities, you might need to retrieve a larger set of results and perform additional filtering in your application code.

It's worth noting that searches in Cognito are case-insensitive, so "julian" will match "Julian" or "JULIAN" as well. Also, remember that you can only search for one attribute at a time using the ListUsers API.

Sources
Managing and searching for user accounts - Amazon Cognito
Cognito ListUsers | AWS re:Post
ListUsers - Amazon Cognito User Pools
UsernameConfigurationType - Amazon Cognito User Pools

answered a year ago
  • Thank you, I understand, but it certainly limits the search capacity to not allow cases as I show above where we have multiple users starting by julian, but we want to limit the scope to julian@. I find the behavior a little inconsistent because it only happens in some regions

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.