Pre token generation Lambda trigger - Unrecognizable lambda output

0

Hi

I followed the Node.js example explained here and I alway get the following exception on Cognito login. {"__type":"InvalidLambdaResponseException","message":"Unrecognizable lambda output"}

The only time it works is, if I call callback immediately without altering the event response

exports.handler = (event, context, callback) => {
    callback(null, event);
};

This example here (copy pasted from the guide) does not work and throws the mentioned exception "Unrecognizable lambda output". Even if I simplify it to this, it throws the same exception:

exports.handler = (event, context, callback) => {
    event.response = {
        "claimsOverrideDetails": {
            "claimsToAddOrOverride": {
                "attribute_key2": "attribute_value2",
                "attribute_key": "attribute_value"
            },
        }
    };

    // Return to Amazon Cognito
    callback(null, event);
};

I also tried to stringily the event, not calling the callback but instead return the event, etc. Always the same result.

An idea anyone?

  • This probably doesn't help, but I had the same issue until I added a 'return event;' after the callback. The weird thing is that it now still works even when I take out the return line.

  • Thanks @rePost-User-7943174 I have tried your approach but I still got the same error.

    After calling callback(null, event) I added the statement return event but it lead to the same error

jetced
gefragt vor einem Jahr664 Aufrufe
1 Antwort
0

So finally I got it to work like this. Instead of overriding the whole response, I only overrode the event.response.claimsOverrideDetails:

exports.handler = async (event, context) => {
    event.response.claimsOverrideDetails = {
         "claimsToAddOrOverride": {
            "attribute_key2": "attribute_value2",
            "attribute_key": "attribute_value"
        }
    };

    return event
};
jetced
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen