Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create user with custom attribute using AdminCreateUser in AWS Cognito

I am trying to create user in AWS Cognito with adminCreateUser API with the below code

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();

var params = {
      UserPoolId: "us-east-1_302HlhnaC", /* required */
      Username : "[email protected]",
      ForceAliasCreation: true,
      TemporaryPassword: '[email protected]',
      UserAttributes: [
        {
          Name: 'given_name', /* required */
          Value: 'test'
        },
        {
          Name: 'family_name', /* required */
          Value: 'kumar'
        },
        {
          Name: 'name', /* required */
          Value: 'test'
        },
        {
          Name: 'custom:dob', /* required */
          Value: '1990-07-25'
        },
        {
          Name: 'email', /* required */
          Value: '[email protected]',
        },
        {
          Name: 'email_verified', /* required */
          Value: 'true',
        }
        /* more items */
      ],

};


cognitoidentityserviceprovider.adminCreateUser(params, function(error, data) {
    console.log(error,data);
    res.send("test");
});

It always throwing following exception : InvalidParameterException: Attributes did not conform to the schema: custom:dob: Attribute does not exist in the schema.

Is am doing anything wrong,if yes please let me know the solution.

Thanks

like image 787
Manoj Thakur Avatar asked May 23 '18 10:05

Manoj Thakur


People also ask

How do I edit a custom attribute in Cognito?

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.

How do I update Cognito attributes?

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


1 Answers

You must add the custom attribute ahead of time. You can create custom attributes by visiting the User Pool and clicking the Attributes link.

like image 57
Darcy Avatar answered Oct 27 '22 05:10

Darcy