When we run user migration lambda and try setting to the username attribute a custom value (our own generated uuid) it doesn’t assign it to that top-level Username field, but adds a username attribute.
const handler = async (event) => {
if (event.triggerSource == "UserMigration_Authentication") {
const user = authenticateUser(event.userName, event.request.password);
if (user) {
event.response.userAttributes = {
username: 'custom_username_goes_here',
};
event.response.finalUserStatus = "CONFIRMED";
event.response.messageAction = "SUPPRESS";
}
}
As a result in the live environment the top-level Username field is set to our custom value, Attributes list has no changes. In the Localstack environment, the top-level Username field is set to some cognito-generated uuid, and a username field is added to the Attributes section.