question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sam local converts an empty response to the string "no data"

See original GitHub issue

Description

We have an API that, for PUTS, POSTS and DELETES returns an HTTP status 200 with no content.

When running the lambda through sam local start-api, SAM seems to change the content to be the string “no data”. I had a quick look in the source (local_apigw_service) and can see this:

body = json_output.get(“body”) or “no data”

The problem manifested to us because out front-end is Angular and were were getting a JSON deserialization error when running locally that we weren’t seeing when running through AWS.

So it looks intentional. But this behaviour is not the same as when I run through the lambda and API gateway.

Steps to reproduce

Lambda returns an HTTP status 200 with no body. In our example, it looks like this:

{‘isBase64Encoded’: False, ‘statusCode’: 200, ‘headers’: {‘Access-Control-Allow-Origin’: ‘localhost’}, ‘body’: None}

Observed result

When running through AWS, I get Content-Length: 0, empty body, http 200.

When running through SAM local, I get Content-Length: 7, with a body “no data”

Expected result

sam local start-api should work the same way as running through AWS, and should never tamper with my data.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 10
  2. sam --version: 0.15.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jfusscommented, Mar 24, 2020

Released in v0.44.0.

Closing

0reactions
johnc44commented, Aug 8, 2019

Setting http 204 response is a great solution, thanks @awood45 awood45. (Ashamed to say I didn’t know that this even existed). Should still be fixed in sam as it shouldn’t be modifying responses, but happy to change my coe to use 204 for no responses.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sam local converts an empty response to the string "no data"
We have an API that, for PUTS, POSTS and DELETES returns an HTTP status 200 with no content. When running the lambda through...
Read more >
sam local invoke - AWS Serverless Application Model
Invoke a local Lambda function using the sam local invoke command from the AWS SAM CLI. ... --no-event, Invokes the function with an...
Read more >
amazon web services - AWS SAM Template - Local Testing
I have a AWS SAM template that I'm trying to test locally and then deploy. The local test runs (sam local start-api) but...
Read more >
Deep Dive into AWS SAM - YouTube
Serverless Application Model ( SAM ) is a template driven tool for creating and managing serverless applications. In just a few lines of...
Read more >
terraform-aws-modules/lambda/aws
Use AWS SAM CLI to test Lambda Function - read more. ... Support builds locally and in Docker (with or without SSH agent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found