Created
May 12, 2022 16:49
-
-
Save harshanas/50032ede06ba56124f6e921d981ef820 to your computer and use it in GitHub Desktop.
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
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