Skip to content

Instantly share code, notes, and snippets.

@leandro-hermes
Created September 22, 2023 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leandro-hermes/1e70ea0c67c4c0d5c94a68e00374922c to your computer and use it in GitHub Desktop.
Save leandro-hermes/1e70ea0c67c4c0d5c94a68e00374922c to your computer and use it in GitHub Desktop.
Delete Cognito users from a pool, filtering by testing e-mails
#!/bin/sh
USER_POOL_ID=XXXXXXXXXX
REGION=us-east-1
PROFILE=XXXXXXXXXX
EMAIL_SUFFIX=@uorak.com
USERS=$(aws \
--profile $PROFILE \
--region $REGION \
cognito-idp list-users \
--user-pool-id $USER_POOL_ID \
--output json \
| jq -r '.Users[] | select(.Attributes[] | select(.Name == "email").Value | endswith("'"$EMAIL_SUFFIX"'")) | .Username'
)
for USER in $USERS; do
# delete users
aws \
--profile $PROFILE \
--region $REGION \
cognito-idp admin-delete-user \
--user-pool-id $USER_POOL_ID \
--username $USER
echo "Deleted user: $USER"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment