4

Is it possible to add Cognito additional custom or standard user attributes post pool creation and once the pool is being used?

In other words is the Schema for the pool totally locked or can we add more custom attributes to it?

Ole
  • 41,793
  • 59
  • 191
  • 359

2 Answers2

4

On AWS Cognito, you have two types of attributes:

  • Standard Attributes: These attributes were selected when the pool was created and cannot be changed.

  • Custom Attributes: These attributes can be added. Once they are added, they cannot be removed or changed

ThomasVdBerge
  • 7,483
  • 4
  • 44
  • 62
  • So once attributes (Custom or standard) have been added does that lock the pool schema? Or can we add additional custom attributes later. Changed can mean many things. For example it could mean that the type of a custom attribute cannot be changed... – Ole Apr 29 '18 at 17:05
  • 1
    You can keep adding new custom attributes indeed. By changed I mean that you can't rename it/change min/max value – ThomasVdBerge Apr 29 '18 at 17:08
3

@ThomasVdBerge is somewhat correct but the answer needs to be more complete and helpful. At this time custom attributes are poorly setup by AWS. For example, you can't find the field you entered in the Console included in user objects returned by various JS SDK api's unless you have a value in it. To do that you have to enter the value with the CLI, which is unworkable for real apps that are meant for users to enter data with a GUI.

The adminCreateUser api doc states this: "For custom attributes, you must prepend the custom: prefix to the attribute name." However, this crashes JavaScript unless you stringify it as below in my edit.

EDIT:

I've added my code for creating a user form. With this setup I can add user ID's and this field will show in the returned object in the console and in the Cognito database of users.

What I've said above is still correct if you want to add data to a custom field and want to do something with it. Adding users with an interface this way works.

const createUserParams = {
    ...
    UserAttributes: [
       {
       Name: 'custom:user_id',
       Value: enteredData.user_id
       },
Preston
  • 3,260
  • 4
  • 37
  • 51
  • I believe you can stringify your object key, like this: params = {'custom:field': 'some value'}. – Vingtoft Jan 17 '19 at 11:32
  • @Vingtoft I added a little of my working code to my answer. I put all attribute names in ' ' and this works for my form. I have full CRUD working for Cognito users. I forgot to go back to this answer and fix it. Thanks! – Preston Jan 17 '19 at 22:21