1
votes

When I test my Lambda through AWS Gateway, I can see this lines being logged:

Wed Jul 19 20:06:11 UTC 2017 : Method response body after transformations: {"errorCode":0,"headers":{},"statusCode":567,"base64Encoded":false}

As you can see I'm returning 567 as status Code. But I always see 200:

enter image description here

Then, this is my configuration in Integration Response:

enter image description here

I'm using as reg exp .*"statusCode":567.*, but it is not matching with {"errorCode":0,"headers":{},"statusCode":567,"base64Encoded":false}.

These are my http status codes in Method Responses section:

enter image description here

I can not make return other than 200. I tried changing the default to be 567 instead of 200. That way it returns 567. So looks like my setting makes my API to return always the default response.

Does anybody have a clue of what I'm doing wrong?

2
I'm not sure if 567 is even a valid status.Noel Llevares
Try using lambda-proxy instead of lambda-integration. That way, you construct your response in your lambda function and not in the API Gateway templates.Noel Llevares
Are any of your errorRegexes .* ? That overrides the default status code logic.Abhigna Nagaraja
567 is a valid status. I ended using lambda-proxy. I can't believe the time I have lost trying to make this work with lambda, and lambda-proxy fixed my issues in 5 mins. @dashmug please add your comment as response and I will vote.Perimosh
@Perimosh Made my comment into an answer. :-)Noel Llevares

2 Answers

2
votes

Try using lambda-proxy instead of lambda-integration.

This way, you construct your response in your lambda function and not in the API Gateway templates.

In my opinion, it's easier to manipulate the response in code rather than using API Gateway templates.

1
votes

In this case, I think it is your regex that is at fault: .*"statusCode":567.*

It's matching on the internal JSON message, so it would need changed to .*\"statusCode\":567.* to match - this worked in my case anyway

I used this answer for mine, slightly simpler that what you are looking for.