InvalidLambdaResponseException for PreSignUp Trigger

0

I keep getting the following error InvalidLambdaResponseException: An error occurred (InvalidLambdaResponseException) when calling the SignUp operation: Unrecognizable lambda output

whether I use boto3's sign_up or the JS signUp function. My trigger lambda is implemented in python and I autoconfirm and verify the user

event['response']['autoConfirmUser'] = True
event['response']['autoVerifyEmail'] = True

and return the event with return event .

The lambda works without any errors but I cannot figure out why I keep getting this error.

  • I followed this up by splitting my presign up lambda to just do auto confirm user and verify the email, the rest of the logic (which creates some user related stuff in our backend via an internal POST call) is in the post confirmation lambda.

    The user is getting created, the post confirmation lambda is running... BUT I still get the error. This is very frustrating, given the lack of documentation by AWS.

1 Answer
0
Accepted Answer

Found the error. We were using the event["request"] values for some internal logic in a separate function and that was modifying the values (forgot that dictionaries are passed by reference since they are mutable). Solved this by making a deep copy (using copy.deepcopy(event["request"])) before passing it on to the function.

Basically looks like the following

from copy import deepcopy

def function_handler(event, context):
    # create a deep copy of the event request
    request = deepcopy(event['request'])
    # do something in our custom function, for us it returns a boolean
    response = do_something(request)
    if not response:
        # since our function did not work as expected, we cannot create the user, raising an exception
        raise Exception('do_something failed, here is an error message that makes sense...')
   
    # since do_something worked, let's confirm the user
    event['response']['autoConfirmUser'] = True
    event['response']['autoVerifyEmail'] = True
    
    return event

This worked. In retrospect, the error Unrecognizable lambda output is not really helpful, if it had more information on the request being modified it would have taken us much less time to figure this out.

answered a year 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.

Guidelines for Answering Questions