0
votes

I have an API gateway endpoint setup that is hooked up to a Lambda function. I've configured a mapping template for the integration between my endpoint and my lambda function which looks like this:

{  
   "httpMethod":"$context.httpMethod",
   "body":"$input.json('$')",
   "queryParams":"$input.params().querystring",
   "headerParams":"$input.params().header",
   "headerParamNames":"$input.params().header.keySet()",
   "contentTypeValue":"$input.params().header.get('Content-Type')",
   "cognitoIdentityId":"$context.identity.cognitoIdentityId",
   "cognitoIdentityPoolId":"$context.identity.cognitoIdentityPoolId",
   "id":"$input.params('id')"
}

I've set up a /{id} path that supports GET and DELETE, both of which have the above mapping template configured.

When I make a GET request, I can see in my CloudWatch logs that the API gateway gets a null request body, processing my mapping, and sends a transformed request body to my lambda with all the expected information filled in.

Method request body before transformations: null
....
Endpoint request body after transformations: {"httpMethod":"GET","body":{},"queryParams":"{}","headerParams":"{....

When I make a DELETE request to the same resource, I see different behavior:

Method request body before transformations: null
....
Endpoint request body after transformations: null

So it seems like there is an issue with the DELETE portion of the API gateway in that it can't handle a null body (an empty body in a DELETE request should be valid as per the HTTP spec).

It all seems to work fine if I pass in an empty body to the DELETE (e.g. set the body to {}). However the API Gateway JavaScript SDK has no way that I can see to pass an empty JSON object; if I pass the generated delete method an empty body it just sets the body of the DELETE request to be null instead of the empty JSON object.

1

1 Answers

2
votes

Would you mind trying to pass in an empty body in string format ("{}")? You might try to use cURL to test your API. Sometime, you might have to pass in Content-Type in header.

I hope those can help you to debug your API.