I'm developing a react native app which uses aws-amplify to interact with amazon cognito. In my use case, I need to ensure value of a custom attribute is unique across all accounts. aws-amplify does not seem to have an API which allows me to search across all accounts by a custom attribute. How can I do this?
Short description. You can't change standard user pool attributes after a user pool is created. Instead, create a new user pool with the attributes that you want to require for user registration. Then, migrate existing users to the new user pool by using an AWS Lambda function as a user migration trigger.
To update a cognito user's attributes use the admin-update-user-attributes command, specifying the user-pool-id , username and user-attributes parameters.
status (called Enabled in the Console) (case-sensitive) Custom attributes are not searchable. For more information, see Searching for Users Using the ListUsers API and Examples of Using the ListUsers API in the Amazon Cognito Developer Guide .
AWS Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. Cognito has two main parts to it : A User Pool acts as a user directory in Cognito. With a user pool, your users can sign in to your web or mobile app through Amazon Cognito.
Sign in to the Amazon Cognito console . In the navigation pane, choose Manage your User Pools, and choose the user pool you want to edit. Choose the Attribute mapping tab. Choose the SAML tab. Select the Capture box for all attributes for which you want to capture values.
From the Amazon Cognito home page in the AWS Management Console, choose Manage your user identities . Choose your user pool from the Your User Pools page. Choose User and Groups to view user information.
Unfortunately you simply can't using Cognito alone:
https://docs.aws.amazon.com/cognito/latest/developerguide/how-to-manage-user-accounts.html#cognito-user-pools-searching-for-users-using-listusers-api
Custom attributes are not searchable. This is because only indexed attributes are searchable, and custom attributes cannot be indexed.
Your only option will be to keep your own database relating the user to the attribute value, and enforce uniqueness there. For example in DynamoDB you would record the user's sub
(unique Cognito identity) and the value of the custom attribute as sort/partition keys accordingly, ensure that normal cognito clients could only read the custom attribute, and provide your own API (lambda + api-gateway) to attempt to add/update the table and use the cognito Admin API to update the 'read-only' custom attribute on the user.
That's correct you can't search custom attribute. Why can't you use one of standard attribute of AWS Cognito to be populated same as custom attribute. Just a thought. Then you can search also to check it uniqueness.
Standard attributes:
username (case-sensitive)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With