- Newest
- Most votes
- Most comments
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
Relevant content
- asked 2 years 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