in lambdas/user-group-importer/index.js [148:196]
for await (const line of await readMigrateLines(event, 'dev-portal-migrate/users.ndjson')) {
if (line) {
const attributes = JSON.parse(line)
const { _isAdmin, _isRegistered, email } = attributes
console.log(`Importing user: ${email}`)
// Don't block - we're doing this as we're also still receiving data from the network.
open++
cognitoIdp.adminCreateUser({
UserPoolId: userPoolId,
Username: email,
UserAttributes: [
...Object.entries(attributes)
.filter(([key]) => key[0] !== '_' && key !== 'sub')
.map(([key, value]) => ({
Name: key,
Value: value
})),
{ Name: 'email_verified', Value: 'True' }
],
MessageAction: 'SUPPRESS'
}).promise().then(() => {
console.log(`Restoring groups for user: ${email}`)
if (_isAdmin) {
// Don't block - we're doing this as we're also still receiving data from the network.
open++
cognitoIdp.adminAddUserToGroup({
UserPoolId: userPoolId,
Username: email,
GroupName: adminsGroup
}).promise().then(pass, fail)
}
if (_isRegistered) {
// Don't block - we're doing this as we're also still receiving data from the network.
open++
cognitoIdp.adminAddUserToGroup({
UserPoolId: userPoolId,
Username: email,
GroupName: registeredGroup
}).promise().then(pass, fail)
}
pass()
}, fail)
}
}