Reputation: 465
I'm trying to process the response from an API gateway -> Lambda -> API gateway exchange, and I can't get the Integration Response to process correctly.
I have 2 API Gateway integration responses defined using the following Lambda Error Regexes:
.*e.* -> method response status 200 (for testing only)
.*500.* -> method response status 500
(no default mapping)
My Lambda returns the following:
if (err)
callback(null, {
statusCode: 500,
message: "commit ID failed - ID already present"
});
else
callback(null, {
statusCode: 200,
message: "new ID committed"
});
So the response from Lambda should always have some data in it.
When I run an API Gateway test it fails to hit either of the rules:
Sat Jun 20 07:49:56 UTC 2020 : Received response. Status: 200, Integration latency: 122 ms
Sat Jun 20 07:49:56 UTC 2020 : Endpoint response headers: {Date=Sat, 20 Jun 2020 07:49:56 GMT, Content-Type=application/json, Content-Length=68, Connection=keep-alive, x-amzn-RequestId=d7556a95-2ff9-4cf2-9e61-cc89484f6548, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5eedbfa4-0ddb3f5e0882fbf1cd7e4674;sampled=0}
Sat Jun 20 07:49:56 UTC 2020 : Endpoint response body before transformations: {"statusCode":500,"message":"commit ID failed - ID already present"}
Sat Jun 20 07:49:56 UTC 2020 : Execution failed due to configuration error: No match for output mapping and no default output mapping configured. Endpoint Response Status Code: 200
If I change the Lambda Error Regexes:
.* matches responses from lambda
.+ doesn't match any responses from lambda
so I think this suggests that whatever field passed to Lambda error regex processing is empty - am I correct, and if so, how do I set a value for it in the Lambda response?
thanks in advance,
Jim
Upvotes: 0
Views: 1111
Reputation: 465
Worked this out - my mistake was in the Lambda function - use callback("error message") for an error, callback(null, "success message") for a success. The API integration response Lambda Error Regex only processes the error (the clue is in the name I guess). So this works:
if (err)
callback("commit ID failed - ID already present");
else
callback(null, {
statusCode: 200,
message: "new ID committed"
});
Now works with a Lambda Error Regex of eg .failed.
Upvotes: 0