I'm getting started with Amazon AWS and integrating JAMStack in their system, following their official tutorial (which includes this video) of a example project.
Everything went smoothly until the creation of a Lambda@Edge Function.
I just created the function and set to trigger at Origin Request from CloudFront. It's just this:
exports.handler = async (event) => {
const REQUEST = event.Records[0].cf.request;
const URI = REQUEST.uri;
return REQUEST;
};
When I go to the root my CloudFront domain, I get my "Hello World" from index.html, which is in a Bucket. However when I go to subpaths, like /404 or non-existing path I get 502 and not 404.html from /404 nor 404.html for non-existing pages.
The role is "Basic Lambda@Edge permissions (for CloudFront trigger)".
I get this:
502 ERROR The request could not be satisfied. The Lambda function result failed validation: The body is not a string, is not an object, or exceeds the maximum size. See Limits in the Amazon CloudFront Developer Guide. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner. If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.