AWS API Gateway: Use Mock Integration to echo response body

I've found this to actually be possible, although a little hacky. First, in the integration request mapping template you store the body in a path parameter.

#set($context.requestOverride.path.body = $input.body)
{
  "statusCode": 200,
}

Then in the integration response mapping template you fetch it back and return it.

#set($body = $context.requestOverride.path.body)
{
  "statusCode": 200,
  "body": $body,
}

This seems to even work well with larger payloads.


You can set up a lambda function for echoing purposing, something like that:

exports.handler = async (event) => {
    return event;
};

Unfortunately this is not supported. In the mapping template for "Integration Response", $input represents the payload received from the integration response (which is empty in the case of a MOCK integration.