By using AWS re:Post, you agree to the Terms of Use

Questions tagged with Amazon Cognito User Pools

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Can't access userAttributes of listUsersRes.Users in AWS lambda function

I'm filtering out unconfirmed emails in lambda function. I jsut want to access email of every user in my listUsersRes.Users. I have tried for listUsersRes.Users[0].Username it is returning username perfectly. But when I'm trying listUsersRes.Users[0].Email or listUsersRes.Users[0] or listUsersRes.Users[0] it is returning null. I have aslo AttributesToGet: ["email"].But I don't know why it is not working for email. **My function:** ``` exports.handler = async (event, context, callback) => { const cognitoProvider = new aws.CognitoIdentityServiceProvider({apiVersion: "2016-04-18"}); if (event.triggerSource == "PreSignUp_SignUp" ||event.triggerSource == "PreSignUp_AdminCreateUser" || event.triggerSource=="PreSignUp_ExternalProvider") { try { const listUserParams={UserPoolId: event.userPoolId,AttributesToGet: ["email"],Filter: `cognito:user_status= \"${"UNCONFIRMED"}\"`, Limit: 10 }; const listUsersRes = await cognitoProvider.listUsers(listUserParams).promise(); if (listUsersRes.Users.length >= 0) { return callback(new Error(listUsersRes.Users[0].Username), event);//this line I'm modifying to get email attribute form listUsersRes.Users[0] } } catch (error) {return callback(new Error("catch error"), event);} } else { var error = "This provider is not supported"; callback(new Error(error), event); } }; ``` **my permission:** ``` "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "logs:CreateLogStream", "logs:PutLogEvents", "cognito-idp:AdminInitiateAuth", "cognito-idp:ListUsers", "cognito-idp:AdminUpdateUserAttributes", "cognito-idp:AdminGetUser" ], ```
asked 2 months ago