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개 답변
0
수락된 답변

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.

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠