我们想要用多个过滤条件过滤掉用户列表,就像node.js中的
email and status
一样。尝试了以下过滤条件,但没有成功。
node.js 的代码片段
const client = new CognitoIdentityProviderClient(<config>);
const inputForFetchUserList = {
Filter: `'email'= '[email protected]' and 'cognito:user_status' = 'FORCE_CHANGE_PASSWORD'`,
UserPoolId: <UserPoolId>, //required
Limit: 5,
};
const commandForFetchUserList = new ListUsersCommand(inputForFetchUserList);
const cognitoListUsersResponse = await client.send(commandForFetchUserList);
const { CognitoIdentityProviderClient, ListUsersCommand } = require('@aws-sdk/client-cognito-identity-provider');
异步函数 listUsersWithFilter() { const client = new CognitoIdentityProviderClient({ 区域: '您的区域' }); // 将 'your-region' 替换为适当的 AWS 区域
// Define your filter conditions
const filters = [
{ Name: 'email', Value: '[email protected]' },
{ Name: 'custom:customAttribute', Value: 'customValue' }
// Add more filter conditions as needed
];
// Set up the ListUsersCommand with the Filters parameter
const listUsersCommand = new ListUsersCommand({
UserPoolId: 'your-user-pool-id', // Replace 'your-user-pool-id' with your actual User Pool ID
Filter: filters
});
try {
// Execute the command
const response = await client.send(listUsersCommand);
// Output the list of users
console.log('Users:', response.Users);
} catch (error) {
console.error('Error listing users:', error);
}
}
// 调用该函数列出带有过滤器的用户 listUsersWithFilter();