i have a function, which read a json with some users informations
i need to create a cognito user for everyone in the json:
const AWS = require("aws-sdk");
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
AWS.config.update({
region: "eu-west-2"
});
const usersJSON = require("./users.json");
let saved = {
Users: []
};
for (let o in usersJSON.Users) {
let { name, surname, userClass } = usersJSON.Users[o];
let emailToSave = `${nome}${cognome}${classe}@spalla.it`;
let email = emailToSave.toLowerCase();
let password = `Pwd${Math.floor(10000 + Math.random() * 90000)}`;
let user = {
nome: name,
cognome: surname,
classe: userClass,
email: email,
password: password,
time: Date()
};
saved.Users.push(user);
let params = {
UserPoolId: cognito.userPoolId,
Username: email,
DesiredDeliveryMediums: [
"EMAIL",
],
MessageAction: "SUPPRESS",
TemporaryPassword: password,
UserAttributes: [{
Name: 'nickname',
Value: name
},
{
Name: 'email',
Value: email
},
{
Name: 'custom:authCode',
Value: "000000"
},
{
Name: 'email_verified',
Value: "True"
},
{
Name: 'custom:userClass',
Value: userClass
},
{
Name: 'custom:role',
Value: "user"
}
]
};
cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
console.log("user created");
});
}
the first time i run this function it does literally nothing, then the second time i run it it creates the two users successfully. ( note: this is only the specific part of the entire code, it was working perfectly some weeks ago.. but now it doesn't. it also includes at the end a function to send an email (nodemailer) with the users created and, as the creation, it works only at the third - fourth time. )
i'm using aws-serverless-express
what could be the problem? thanks in advance!