Skip to content

conflicting Lambdas?

0

Hi,

in order to be able to customize the message and landing page, I have successfully implemented the flow according to the following procedures

https://medium.com/@jacobjoy/redirect-user-using-amazon-cognito-confirmation-url-d8ccb11bac75

however, I need to update my DB when the user confirms his email by clicking on the link in the verification email I therefore created another lambda to be triggered on "Post confirmation" but now if the user clicks the link in the email, he gets redirected to the error page even if he results confirmed in the user pool and the DB is correctly updated. Everything works if I remove the lambda with the "Post confirmation" trigger. How can I achieve the goal of updating the db when the user clicks successfully on the confirmation link?

this it the lambda with "Post confirmation" trigger:

const axios = require("axios");

exports.handler = async (event, context, callback) => {

  console.log("Authentication successful");
  console.log("Trigger function =", event.triggerSource);
  console.log("User pool = ", event.userPoolId);
  console.log("App client ID = ", event.callerContext.clientId);
  console.log("User ID = ", event.userName);
  console.log("event = ", event.request.userAttributes.email);
  const data = {
    email:event.request.userAttributes.email,
    key:process.env.KEY
  }
   
  await axios.post(`${process.env.BASE_URL}/api/ac/user-confirm`,data )
  callback(null, event);
};


whereas this is the Lambda to Confirm the user in Cognito, as described in the tutorial mentioned above

"use strict";
var AWS = require("aws-sdk");
AWS.config.setPromisesDependency(require("bluebird"));
var CognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({
  apiVersion: "2019-11-07",
  region: process.env.REGION,
});
const axios = require("axios");

exports.handler = (req, context, callback) => {
  console.log(req);
  const confirmationCode = req.code;
  const username = req.username;
  const clientId = req.clientId;
  let params = {
    ClientId: clientId,
    ConfirmationCode: confirmationCode,
    Username: username,
  };
  //Validating the user
  let confirmSignUp =
    CognitoIdentityServiceProvider.confirmSignUp(params).promise();
  //Returning the redirect url
  confirmSignUp
    .then(async (data) => {      
      context.succeed({
        location: process.env.POST_REGISTRATION_VERIFICATION_REDIRECT_URL,
      });
    })
    .catch((error) => {
      //callback(error.message);
      console.log("ERROR: ", error);
      if (error.code == "ERR_BAD_RESPONSE") {
        context.succeed({
          location: process.env.POST_REGISTRATION_VERIFICATION_REDIRECT_URL,
        });
      } else {
        context.succeed({
          location: process.env.POST_REGISTRATION_VERIFICATION_INVALID_LINK,
        });
      }
    });
};

  • Is there anything in Cloudwatch logs for the lambda?

  • yes, it says that UserLambdaValidationException: PostConfirmation failed with error 2023-01-30T15:44:55.664Z 71d18d9b-0dfd-42d5-8b28-bf3610acafae Task timed out after 3.01 seconds.

    however, in the configuration I raised the timeout to 10 minutes but, as explained, the user status results as "confirmed" despite the error....

2 Answers
0
Accepted Answer

yes, probably it was an error in my env var

answered 3 years ago
EXPERT
reviewed 2 years ago
0

Post Confirmation is called after the confirmation is done, so the that fact the user is Confirmed does not come from your Lambda function.

Also what are the logs at the endpoint ${process.env.BASE_URL}/api/ac/user-confirm ?

AWS
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.