Skip to content

Instantly share code, notes, and snippets.

@harshanas
Created May 12, 2022 16:49
Show Gist options
  • Save harshanas/50032ede06ba56124f6e921d981ef820 to your computer and use it in GitHub Desktop.
Save harshanas/50032ede06ba56124f6e921d981ef820 to your computer and use it in GitHub Desktop.
const AWS = require('aws-sdk');
const accessKeyId = ""
const secretAccessKey = "";
const region = "";
const userPoolId = "";
AWS.config.update({
accessKeyId,
secretAccessKey,
region,
});
async function main(){
const cognito = new AWS.CognitoIdentityServiceProvider();
let count = 0;
let pToken = "dummy_token";
let users = [];
while(pToken){
if (pToken != "dummy_token"){
list = await cognito.listUsers({
UserPoolId:userPoolId,
PaginationToken:pToken
}).promise()
}else{
list = await cognito.listUsers({
UserPoolId:userPoolId,
}).promise()
}
for(user of list.Users){
users.push(user.Username);
count++;
}
pToken = list.PaginationToken;
}
for (user of users){
await cognito.adminDeleteUser({
UserPoolId:userPoolId,
Username: user
}).promise();
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment