Hi Team, I am facing some strange issues with Cogn...
# help
m
Hi Team, I am facing some strange issues with Cognito triggers and local testing. I created a presignup lambda trigger and directly did
context.done(null, event);
. on another lambda which I am running locally, I am trying to call signup. the trigger executes successfully but Cognito is throwing an error. (if I remove the trigger, everything works fine)
a
could you share the register handler, it says invalid JSON for register.
m
Hi, thanks for replying. It worked when I removed the trigger from Cognito. I am going to deploy to check if the issue persists.
a
okay. 👍
m
Deployed lambda worked fine. This is only happening with local testing.
a
wow! that’s weird.
m
yep, and issue exist in local testing.
I think I kind of understand why this is happening, below ss is how my presignup trigger logs looks like when local testing. vs what I expect and receiving after it's deployed. (Conclusion is sst.Function cannot be used with cognito triggers. and cognito triggers cannot be local tested.) @Frank tagging you for issue visibility. I am going to replace the sst.function with CDK.function for the triggers.
f
Hey @Mr.9715 this seems to be the issue
{"type":"success","data":null}
. If you are simply returning the event object:
Copy code
context.done(null, event)
Any idea why “data” is null?
m
Hey @Frank, No idea where the event goes, I logged the event and I can see the event object received by the trigger function both locally and when deployed. for some reason, this event is lost when the message is transmitted through lambda proxy when local testing.
f
Change:
Copy code
export.handler = function(event, context) {
  context.done(null, event)
}
to:
Copy code
export.handler = function(event, context, callback) {
  callback(null, event);
}
SST currently doesn’t support
context.done
as it’s the deprecated way to send the response back. Starting
nodejs10.x
, Lambda switched to using the
callback
Give it a try!
m
Hi @Frank, It worked. But I faced another issue. callback is not returning the errors that I am explicitly throwing. it instead returns
InvalidLambdaResponseException
when I don't return an event and
{ "type": "success", body: none/event }
when i do
callback(new Error("an error")). or callback("Error") or callback("Error", event)
In any case caller doesn't receive the error message when using callback or return. This however worked with context.done(), fail etc. *Issue on cognito side
I am trying to deny creation of account for existent users in the presignup triggrr. If user creates an account with email and add /verify phone no. later. (and pool allows signin with both email, phone and username), everything works fine until another user tries to create an account with same phone to which cognito creates new account and marks phone as unverified in previous account.
f
Does this work
callback(new Error("an error"), event)
?
m
Nope, it returns success every time i return event. with or without error.
f
The issue you are running into doesn’t seem to be Cognito trigger related anymore. It’s simply
callback(new Error("My Error"), event);
isn’t triggering the error. So I just tried this:
Copy code
export function main(event, context, callback) {
  const error = new Error("my error");
  callback(error, event);
}
And I’m seeing an error when invoked:
Maybe try with a simple Lambda and see if you can reproduce the issue?
m
Ah, You are right. I was missing a
return
on line 20. 😂 Sorry for the false alarm.