How to Update Cognito User Attributes

avatar

Borislav Hadzhiev

Fri Sep 24 20212 min read

banner

Photo by Suhyeon Choi

Update Cognito User Attributes #

User pool attributes in Cognito are of 2 types:

  • standard - the default user attributes you get with every user pool
  • custom - user attributes specific to your application, that are not supported by default

This article shows how to update both types.

To update a cognito user's attributes use the admin-update-user-attributes command, specifying the user-pool-id, username and user-attributes parameters.

Let's look at an example of how to update the standard attributes of a cognito user:

shell
aws cognito-idp admin-update-user-attributes --user-pool-id YOUR_USER_POOL_ID --username john@example.com --user-attributes Name="gender",Value="m" Name="name",Value="john smith"

update standard user attributes

In the example above, we've set the gender attribute of the user to m and their name attribute to john smith.

The admin-update-user-attributes command enables us to update a cognito user's attributes, including verify their email.

The --user-attributes parameter expects space separated name-value pairs, representing user attributes.

To find a complete list of all standard user attributes visit the docs.

Let's now look at an example of how to update the custom attributes of a cognito user:

shell
aws cognito-idp admin-update-user-attributes --user-pool-id YOUR_USER_POOL_ID --username john@example.com --user-attributes Name="custom:bio",Value="Hello World" Name="custom:country",Value="Chile"

update custom user attributes

In the example above, we've set the user's custom bio attribute to Hello World and their custom country attribute to Chile.

When updating custom user attributes, you must prefix the name of the attribute with custom:.

To verify that the cognito user's attributes have been updated successfully, run the admin-get-user command.

shell
aws cognito-idp admin-get-user --user-pool-id YOUR_USER_POOL_ID --username john@example.com

verify user attributes updated

The admin-get-user command returns information about the user, including the complete list of the user's attributes.

The output of the command shows that the standard and custom cognito user attributes have been updated successfully.

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee