I am trying to remove some headers from a Cloudfront response using Lambda@Edge on the ViewerResponse event. The origin is an S3 bucket.
I have been successful to change the header like this:
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
response.headers.server = [{'key': 'server', 'value': 'bunny'}];
callback(null, response);
};
However it does not seem to work to remove headers all together, e.g. like this.
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
delete response.headers.server;
// or response.header.server = null;
// or response.headers.server = [{'key': 'server', 'value': null}];
callback(null, response);
};
This snippet does not remove but changes the server header from server: AmazonS3 to server: CloudFront. So I assumed that maybe the server header is mandatory and gets populated automatically. But I also not have been able to remove other headers that are generated by CloudFront. In the lambda test pane, the function works as expected. So something is happening after the Lambda function finishes.
As a background, I would like to change the headers because the site gets blocked in an important client's network with the message that it was an online storage-or-backup location.
What am I missing?
X-Amz-Cf-*headers, which should be the only relevant headers that you can't remove or modify from a viewer response trigger -- and it would be inappropriate to classify a site as "storage or backup" based on these things since CloudFront is neither, and is widely used by many sites as a CDN. Are you using a custom domain on your CloudFront distribution, or are you using the system-assigned*.cloudfront.netdomain name? If you're not using a custom domain, that's much more likely to be the problem. Please confirm. - Michael - sqlbot