Hi! I’m trying to create a new user using Accounts and create IAMuser.
The IAM resources are created but I don’t have the user on Mongo. If I commented the creation of IAM resources, the user is created on Mongo. I don’t understand it. Do you have any idea?
Thanks
async createUser(user) {
try {
//create IAM USER
const userName = `${user.firstName}${user.lastName}`;
await this.createIAMUser(userName, user.company);
//add user to the IAMgroup
await this.addIAMUserToGroup(userName, user.company);
//add user to nonCompanyGroupCommon group
await this.addIAMUserToGroup(
userName,
'nonCompany',
user.company
);
// create user accessKey on IAM service
const awsUserKeysInfo = await this.createIAMUserAccessKey(
userName,
user.company
);
Accounts.onCreateUser((options, user) => {
if (!options) {
throw Error('Could not create the user');
}
user.firstName = options.firstName;
user.lastName = options.lastName;
user.company = options.company;
user.accessKeyId = awsUserKeysInfo.AccessKeyId;
user.secretAccessKey = awsUserKeysInfo.SecretAccessKey;
if (!user.accessKeyId) {
throw Error('Could not create the user');
}
return user;
});
return user;
} catch (error) {
await putLogsErrorsOnCloudWatch({
company: user.company,
error: error,
errorMessageLabel: 'createUserError',
logGroup: constants.CLOUDWATCH,
});
}
}