Why would I want to only keep the body content?
One of the lambdas (let's call it X
) in our project is being invoked by another lambda, and this is the only organic way we'd like X
to be executed.
Input passed to X through its lambda invoker:
{
"foo" : "foo_value",
"bar" : "bar_value"
}
-- Writing general integration tests, we can simply invoke X
with the expected event, and it works great.
-- However, for our acceptance tests, we need to invoke X
in isolation from AWS rather than locally, and this can only be done via API Gateway
-- ==> so we created a POST event source for X
that will only be used for test purposes.
The event sent by API Gateway
to X
:
{
headers : {
"some-headers1": "some-value1",
....
"some-headersn": "some-valuen",
},
body : {
"foo" : "foo_value",
"bar" : "bar_value"
},
.....
.....
}
The problem that we're looking to solve:
Is there a way to convert the API input to exactly what we're expecting from the lambda invoker?
In other words, Is it possible to write a custom request integration mapping template for the POST endpoint in order to only keep event.body
?
And by that I mean : $util.escapeJavaScript($input.json('$'))
and not { body: $util.escapeJavaScript($input.json('$')) }
Why?
We can simply add a few lines of code into X
to ignore the extra information generated by the API Gateway, but since API Gateway is not part of the organic execution events, we don't wish to alter X
to transform the received event.
How would it be possible?