Whenever I am trying to add response headers, the CloudFront throws me the
ERROR Validation error: Lambda function result failed validation, the function tried to delete read-only header, headerName : Content-Length.
ERROR Validation error: Lambda function result failed validation, the function tried to delete read-only header, headerName : Content-Encoding.
const response = {
status: '302',
statusDescription: 'Found',
headers: {
'location': [{
key: 'location',
value: 'https://abc.test.io'
}],
'set-cookie': [{
key: 'set-cookie',
value: 'sessiontoken=' + sessionObjectData.session.sessionId + '; Secure; HttpOnly'
}]
}
};
callback(null, response);
Can someone let me know what I am doing wrong here ? BTW, I am using viewer-response event
As mentioned on CloudFront functions docs, it is not possible to modify some of the response headers from Edge Functions (including Content-Length). What you can try instead is to update only headers you need to change and left others untouched:
const response = event.Records[0].cf.response;
response.status = 302;
response.statusDescription = 'Found';
response.headers['location'] = [{ key: 'Location', value:'https://abc.test.io'}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With