Aws-sdk-js: AWS.CognitoIdentityServiceProvider's adminCreateUser returns "UserNotFoundException: User does not exist."

Created on 11 Feb 2017  路  5Comments  路  Source: aws/aws-sdk-js

Hello,

I'm trying to create a new user. There are currently no users at all in my user pool. I've checked in the console and programatically by calling deleteUser. I'm also super confused why a "create user" command would return "user not found". Of course the user isn't found... that's why I'm creating it. :-)

I'm using AWS SDK 2.12.0 and Node 4.6.0 on Windows 10. Here's the code I'm calling:

  var params = {
    UserPoolId: "@cognito_pool_id@",
    Username: email.replace("@", "__"),
    DesiredDeliveryMediums: ["EMAIL"],
    ForceAliasCreation: false,
    MessageAction: "RESEND",
    TemporaryPassword: tempPassword,
    UserAttributes: [
      { Name: "given_name", Value: firstName },
      { Name: "family_name", Value: lastName},
      { Name: "name", Value: firstName + " " + lastName},
      { Name: "email", Value: email},
      { Name: "custom:title", Value: "Made up title"},
      { Name: "custom:company", Value: companyName},
      { Name: "phone_number", Value: "+15124262345"}
    ],
  };
  console.log("Sending params to cognito: " + JSON.stringify(params));
  var cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({region: "us-east-1"});
  cognitoIdentityServiceProvider.adminCreateUser(params, function(error, data) {
    if (error) {
      console.log("Error adding user to cognito: " + error, error.stack);
    } else {
      console.log(data);
      module.exports.addUserToDB(firstName, lastName, email, "Rockets R US", "XXXXXXXX", callback);
    }
  });

My log statement prints the following, which looks good to me. I X'd out the UserPoold. The rest is fake test data including the phone num:

Sending params to cognito: {"UserPoolId":"us-east-1_XXXXXXXXX","Username":"qdbvision-test__mailinator.com","DesiredDeliveryMediums":["EMAIL"],"ForceAliasCreation":false,"MessageAction":"RESEND","TemporaryPassword":"23x3l.023LQ","UserAttributes":[{"Name":"given_name","Value":"Ryan"},{"Name":"family_name","Value":"Rocket"},{"Name":"name","Value":"Ryan Rocket"},{"Name":"email","Value":"[email protected]"},{"Name":"custom:title","Value":"Made up title"},{"Name":"custom:company","Value":"Rockets R US"},{"Name":"phone_number","Value":"+15124262345"}]}

When the error arrives, here's the output/stack trace:

Error adding user to cognito: UserNotFoundException: User does not exist. UserNotFoundException: User does not exist.
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:921:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickDomainCallback (node.js:397:17)

I can add a very similar user with the exact same username & email through the browser using "amazon-cognito-identity-js" on our sign-up pages. I wanted a quick way to do this on the back-end as a setup for test cases.

Any idea why I'm receiving this "UserNotFoundException"?

guidance

Most helpful comment

Hi @neerajaset71,

That's the intended behavior if you set the MessageAction parameter to 'SUPRESS'. To create a new user and send a notification email, omit the MessageAction parameter.

All 5 comments

I haven't set up a repro case for this yet, but wouldn't you expect to encounter a UserNotFoundException when the MessageAction parameter is set to RESEND? The API reference implies that the "RESEND" action should only work on existing users.

Yup. Right you are. Changing RESEND to SUPPRESS fixed it. Sorry to bother you!

but are you getting welcome email with temp password after this change? I am not getting..what am I missing?

Hi @neerajaset71,

That's the intended behavior if you set the MessageAction parameter to 'SUPRESS'. To create a new user and send a notification email, omit the MessageAction parameter.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings