Reputation: 8137
I have Lambda function written in Python 2.7 which is triggered from API Gateway,
I want API Gateway to return 400 code when Lambda fails and I don't want to use Lambda Proxy so I'm trying to set API Gateway Integration Response.
When Lambda function fails it returns:
{
"stackTrace": [
[
"/var/task/lambda_function.py",
12,
"lambda_handler",
"raise Exception('failure')"
]
],
"errorType": "Exception",
"errorMessage": "failure"
}
Lambda Error Regex and Body Mapping template:
..the same from CLI:
aws apigateway get-integration-response --rest-api-id bz47krygwa --resource-id 788q0w --http-method ANY --status-code 400 --region us-west-1
{
"statusCode": "400",
"selectionPattern": ".*\"failure\".*",
"responseTemplates": {
"application/json": "#set($inputRoot = $input.path('$.errorMessage'))\n$inputRoot"
}
}
..but it doesn't work correctly and still returns 200 code:
any advice on fix please?
Upvotes: 5
Views: 10231
Reputation: 8137
Answer turned out to be very simple - removing double quotes from Lambda Error Regex did the trick,
moreover Body Mapping template could also be removed:
Upvotes: 6