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.
subattribute)