How to return nothing in AWS API Gateway?

Viewed 3979

Sorry for this dumb question, but I tried everything.

I have a AWS API Gateway from a Lambda function that I need to return only HTTP Code 200 with no body. If the lambda returns a empty string, the body shows "" (2 quotation marks). If the lambda returns null, the body shows the word null.

What is the catch? How to return a empty body?

For information, I am using a Slack dash command to call the API. So the call returns a HTTP 200 OK, and the result is sent by POST in a response url; so processing can be done after the HTTP result, in order to avoid timeout problems.

2 Answers

I experienced exact the same issue. Lambda Proxy Integration didn't work for me. (Lambda didn't received the request from API Gateway. I think the Proxy disabled Integrated Request > Mapping Template, which transforms slack's application/x-www-form-urlencoded into JSON that Lambda can read.)

Instead, I got another resolution: using Integrated Response. Selected 200 and added Mapping Template then fill in the following code:

#set($inputRoot = $input.path('$'))

After saving and deploying the API (Be sure to return null in the Lambda Function), I got the problem solved. (In my case, I wanted to hide the slash command the user typed in and only show the results.)

I've referenced this article: https://medium.com/@farski/learn-aws-api-gateway-with-the-slack-police-ca8d636e9fc0

Related