cogito.adminSetUserPassword is not a function in aws lambda

Viewed 940

When i'm trying to use cognito.adminSetUserPassword in aws lambda the console says: cognito.adminSetUserPassword is not a function but when i'm trying in localhost its works fine. The current code is the follow y nodejs with express.

module.exports.set_password = async (req, res) => { 
  try {
   const cognito = new AWS.CognitoIdentityServiceProvider({
    region: process.env.AWS_REGION,
   });

   const { id: Username } = req.params;
   const newPassword = 'newPassword@12333'

   await cognito.adminSetUserPassword({
    UserPoolId: process.env.USERPOOL_ID,
    Username,
    Password: newPassword,
    Permanent: false,
   }).promise();

  } catch (error) {
     console.log(error);
     res.status(error.code).json({
      code: error.code,
      message: error.message,
     });
  }
};
2 Answers

If your lambda function is nodejs, then set below stuff in your package.json and that will enable the required.

  • "amazon-cognito-identity-js": "^4.5.7",
  • "aws-sdk": "^2.828.0",
Related