0

I am creating a Mock endpoint to work on a development project.

I want to throw certain response codes based on the strings in the JSON request body.

E.g.

{ "desiredResponse": "200" }

Would return a response code of 200.

{ "desiredResponse": "400" }

Would return a response code of 400.

From my understanding, this is not possible via the Mock Integration Response (Reference: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html)

Is this possible via a Lambda function? Or is there any possible workarounds for this?

Due to the nature of this project, I do not want to use request Query Strings or Header to set the response code.

I have seen the workarounds here, https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html but I really need the response code to be dependant on the request data.

fuzzi
  • 1,967
  • 9
  • 46
  • 90
  • This would be easily done with a [Lambda Proxy Integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html). – Michael - sqlbot Aug 14 '18 at 01:43

1 Answers1

0

First: Use a Lambda Proxy Integration to output a particular error to the JSON response body.

Then, use the API Integration Response to map the error string to the particular status code using the Lambda Error Regex field.

fuzzi
  • 1,967
  • 9
  • 46
  • 90