我正在尝试编写一个 bash 脚本来确认 Cognito 用户池中所有未确认的用户。文档here说我可以使用cognito:user_status按状态过滤。所以我写了这段代码。
#!/bin/bash
USER_POOL_ID=pool_id
RUN=1
until [ $RUN -eq 0 ] ; do
echo "Listing users"
# Here is the problem after the --filter param. How should I query for the unconfirmed users?
USERS=`aws --profile jaws-lap cognito-idp list-users --user-pool-id ${USER_POOL_ID} --filter 'cognito:user_status="unconfirmed"' | grep Username | awk -F: '{print $2}' | sed -e 's/\"//g' | sed -e 's/,//g'`
if [ ! "x$USERS" = "x" ] ; then
for user in $USERS; do
echo "Confirming user $user"
aws --profile jaws-lap cognito-idp admin-delete-user --user-pool-id ${USER_POOL_ID} --username ${user}
echo "Result code: $?"
echo "Done"
done
else
echo "Done, no more users"
RUN=0
fi
done
问题是 --filter 配置不正确。我应该如何写声明才能获得未经确认的用户?
谢谢。
这个命令对我有用:
aws cognito-idp list-users --user-pool-id xxx --filter 'cognito:user_status="CONFIRMED"'
要过滤掉用户的确认状态,请在您的 fitler 参数中使用 cognito:user_status
常量参数 = { 用户池Id:用户池Id, 过滤器:
cognito:user_status="FORCE_CHANGE_PASSWORD"
,
PaginationToken:分页令牌
};