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.

1
  • What does your API Gateway endpoint's response mapping template look like?
    – Mark B
    Commented May 12, 2017 at 14:04

2 Answers 2

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);
};
1
3

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

1
  • In fact any valid mapping template expression works. The shortest one appears to be specifying ## because that signals a comment.
    – luk2302
    Commented Jun 14 at 15:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.