Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

204 api lambda responses fail aws cloudfront validation due to body property inclusion #436

Closed
joemclo opened this issue Jun 10, 2020 · 1 comment · Fixed by #437
Closed

Comments

@joemclo
Copy link
Contributor

joemclo commented Jun 10, 2020

Describe the bug

When returning a status code of 204 in the response of a next api route, AWS lambda at edge raises an validation error Response Contains a Body and Specifies 204 (No Content) for Status due to the presence of the body property in the response object.

To Reproduce

Take an example next api handler

export default (req, res) => {
    res.status(204).end();
};

The res object with be transformed into a lambda at edge response object by

packages/lambda-at-edge-compat/next-aws-cloudfront.js:handler

However this does not take into account the need to omit the body object with a 204 response as detailed here under errors:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses-in-requests.html

So for a 204 status response, a body property with an empty value is included and the cloudfront validation fails.

Expected behavior
If an API handler returns a status of 204, the cloudfront response object should omit the body property.

@danielcondemarin
Copy link
Contributor

A fix should be available in: [email protected] 🥳 Let me know if you are still having issues.

FinnWoelm added a commit to netlify/next-on-netlify that referenced this issue Jul 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants