Skip to content

Instantly share code, notes, and snippets.

@aleofreddi
Last active September 20, 2024 16:13
Show Gist options
  • Save aleofreddi/87aea38a9896df30cc8c41e1721013f7 to your computer and use it in GitHub Desktop.
Save aleofreddi/87aea38a9896df30cc8c41e1721013f7 to your computer and use it in GitHub Desktop.
AWS Cognito: list all users
#!/bin/sh
#
# Dump AWS Cognito users as CSV output.
#
# Thu Jun 20 15:31:10 CEST 2019, Andrea Leofreddi
#
me="`basename $0`"
if [ $# != 1 ]; then
echo Usage: "$me" pool_id >&2
exit 1
fi
next=''
tmpfile="`mktemp "$me".XXXXXX`"
trap 'rm -f "$tmpfile"' EXIT
while :; do
if ! aws cognito-idp list-users --user-pool-id "$1" --limit 60 "$next" > "$tmpfile"; then
echo ERROR: list-users failed >&2
exit 10
fi
jq --arg next "${#next}" -r '.Users | map_values((.Attributes | from_entries) + { username: .Username, userstatus: .UserStatus, enabled: .Enabled }) | if $next == "0" then (.[0] | to_entries | map(.key)) else empty end, (.[] | [.[]]) | @csv' < $tmpfile
token="`jq -r '.PaginationToken' "$tmpfile"`"
if [ "$token" = null ]; then
break
fi
next=--pagination-token="$token"
sleep 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment