cognitoHelper.prototype.createAdminUser = function()

in source/resources/helper/lib/cognito-helper.js [178:242]


    cognitoHelper.prototype.createAdminUser = function(userPoolId, adminName, adminEmail, appUrl, cb) {
        let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
        var params = {
            UserPoolId: userPoolId,
            AdminCreateUserConfig: {
                AllowAdminCreateUserOnly: true,
                InviteMessageTemplate: {
                    EmailMessage: [
                        'You are invited to join the Data Lake. Your Data Lake username is {username} and temporary password is {####}. \n \n Please sign in to the Data Lake with your email address and your temporary password at',
                        appUrl, '.'
                    ].join(' '),
                    EmailSubject: 'Your Data Lake account.',
                    SMSMessage: 'Your username is {username} and temporary password is {####}.'
                },
                UnusedAccountValidityDays: 7
            },
            MfaConfiguration: 'OFF',
            AutoVerifiedAttributes: ['email'],
            Policies: {
                PasswordPolicy: {
                    MinimumLength: 8,
                    RequireLowercase: true,
                    RequireNumbers: true,
                    RequireSymbols: false,
                    RequireUppercase: true
                }
            }
        };
        cognitoidentityserviceprovider.updateUserPool(params, function(err, data) {
            if (err) {
                return cb(err, null);
            }

            var _userName = adminEmail.replace('@', '_').replace(/\./g, '_').toLowerCase();
            var _password = generatedSecurePassword();
            let params = {
                UserPoolId: userPoolId,
                Username: _userName,
                DesiredDeliveryMediums: ['EMAIL'],
                ForceAliasCreation: true,
                TemporaryPassword: _password,
                UserAttributes: [{
                    Name: 'email',
                    Value: adminEmail.toLowerCase()
                }, {
                    Name: 'email_verified',
                    Value: 'true'
                }, {
                    Name: 'custom:role',
                    Value: 'Admin'
                }, {
                    Name: 'custom:display_name',
                    Value: adminName
                }]
            };

            cognitoidentityserviceprovider.adminCreateUser(params, function(err, newUserData) {
                if (err) {
                    return cb(err, null);
                }

                return cb(null, {Username: _userName});
            });
        });
    };