0

I am trying to create a UUID for a Cognito user upon signup but also want to make it immutable. Currently I am using the AWS Pre-signup trigger but because UUID is immutable and called after the Cognito user is created, it is giving the error "errorType":"InvalidParameterException","errorMessage":"user.custom:uuid: Attribute cannot be updated." Do I have to make UUID mutable or is there another workaround?

import { uuidv7 } from 'uuidv7';
import {
   AdminUpdateUserAttributesCommand,
   CognitoIdentityProviderClient
 } from "@aws-sdk/client-cognito-identity-provider";
 
 export const handler = async (event, context, callback) => {
   console.log(event);
   const client = new CognitoIdentityProviderClient({});
   let uuid = uuidv7();
   console.log(uuid);
   console.log(uuid.length);
   await client.send(new AdminUpdateUserAttributesCommand({
      UserAttributes: [
          {
              Name: 'custom:uuid',
              Value: uuid
          }
      ],
      UserPoolId: 'userpoolid',
      Username: event.request.userAttributes['username']
  }))
   
   callback(null, event);
 };
 
 

I can make the UUID mutable, but I would prefer not to do that.

2
  • 1
    Why do you want to generate UUID for users? Cognito does this for you out of the box (sub attribute) Commented May 23 at 10:08
  • It's because I want to use it as a primary key in a database and if i want to migrate user pools later, uuid stays while the sub of each user would change. Commented May 23 at 23:49

1 Answer 1

0

With the approach you are currently using, you would have to make it mutable. If you want to make the uuid immutable, you have to provide it during the user sign up process, along with other attributes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.