Last active
October 2, 2019 19:57
-
-
Save dehli/15bacb87d57ac2b5df5e69d641899680 to your computer and use it in GitHub Desktop.
clear_cognito_pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { USER_POOL_ID } = process.env; | |
if (!USER_POOL_ID) throw new Error("Missing USER_POOL_ID"); | |
const AWS = require("aws-sdk"); | |
const cognito = new AWS.CognitoIdentityServiceProvider(); | |
const attribute => ({ Attributes }, name) => | |
Attributes.filter(a => a.Name === name)[0].Value; | |
const shouldDelete = user => | |
attribute(user, "email").indexOf("dev+") > -1; | |
(async function() { | |
while (true) { | |
const { Users } = await cognito.listUsers({ UserPoolId: USER_POOL_ID }).promise(); | |
let deletedUsers = 0; | |
for (const user of Users) { | |
if (shouldDelete(user)) { | |
await cognito.adminDeleteUser({ | |
UserPoolId: USER_POOL_ID, | |
Username: user.Username | |
}).promise(); | |
deletedUsers++; | |
} | |
} | |
if (deletedUsers === 0) break; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment