#TIL 6 - Delete all users from AWS Cognito | ProductsWay

#TIL 6 - Delete all users from AWS Cognito

Sep 1, 2020 · Dung Huynh

What

Delete every user in an AWS Cognito user pool using the AWS CLI.

Why

Cognito has no "delete all users" button. After integration tests, the AWS CLI can auto-paginate list-users and pipe every username into admin-delete-user. Preview the usernames first and run this only against the intended test pool because deletion cannot be undone.

How

aws cognito-idp list-users --user-pool-id POOL_ID \
  | jq -r '.Users | .[] | .Username' \
  | while IFS= read -r uname; do
      aws cognito-idp admin-delete-user \
        --user-pool-id POOL_ID \
        --username "$uname"
    done