serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

Lambda@Edge origin response event errors out with 502 error because read-only header was deleted

Open rdsedmundo opened this issue 3 years ago • 2 comments

The Cloudfront request responds with: The Lambda function result failed validation: The function tried to add, delete, or change a read-only header. 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.

From CloudWatch logs: ERROR Validation error: Lambda function result failed validation, the function tried to delete read-only header, headerName : Transfer-Encoding.

I've figured out a workaround that is to just copy the header manually, but I wonder if the library should've taken care of that itself?

import { getCurrentInvoke } from '@vendia/serverless-express';

router.get('/*', (req, res) => {
  const { event } = getCurrentInvoke();

  if (event.Records[0].cf.response.headers['transfer-encoding']) {
    res.setHeader(
      'Transfer-Encoding',
      event.Records[0].cf.response.headers['transfer-encoding'][0].value,
    );
  }

rdsedmundo avatar Feb 11 '21 18:02 rdsedmundo

Thanks, I'll take a look.

brettstack avatar Feb 12 '21 22:02 brettstack

I see this is origin-response. I've only tested with viewer-request and origin-request. Could you provide more details on your use case? Alternatively, does viewer-request or origin-request fit your use case?

brettstack avatar Feb 14 '21 10:02 brettstack