Sam local converts an empty response to the string "no data"
See original GitHub issueDescription
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)
- OS: Windows 10
sam --version
: 0.15.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Released in v0.44.0.
Closing
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.