9

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295
TNT
  • 819
  • 1
  • 8
  • 28

2 Answers2

5

If you are using the "lambda proxy integration" in the "integration request" section (see attached screenshot), you can simply return an empty string through the following structure.

enter image description here

module.exports.hello = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: ''
  };
  callback(null, response);
};
jens walter
  • 13,269
  • 2
  • 56
  • 54
  • 2
    Took me a while to figure how to change the function input (I'm using C#). For anyone come here: http://stackoverflow.com/questions/41283289/how-do-i-map-aws-api-gateway-query-string-to-c-sharp-aws-lambda-function – TNT May 12 '17 at 17:18
2

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