从 AWS CloudFront 中删除 Cache-Control headers?

Remove Cache-Control headers from AWS CloudFront?

我正在从我的源服务器设置 Cache-Control:s-maxage=3600。通过这个,我指示我的 AWS CloudFront 将内容缓存 3600 秒。我已将一些 cookie 列入白名单,并根据 CloudFront 中的 cookie 值设置缓存。在客户端和我的 CloudFront 之间没有代理之前,此设置工作正常。

如果有Proxy,由于s-maxage header也会缓存一个版本,不考虑cookie值。因此,我的最终用户看到了我网页的不相关版本。

有什么办法可以克服这个问题吗?或者我需要编写一个 Lambda@edge 函数来删除 Viewer Response 中的 Cache-Control:s-maxage=3600?

在查看器响应中创建 Lambda@Edge 函数并重置 Cache-Control header。

exports.handler = (event, context, callback) => {

    /* Get response */
    const response = event.Records[0].cf.response;       

    response.headers['cache-control'] = [{
        key: 'cache-control', value: 'no-cache, no-store, must-revalidate'
    }];

    callback(null, response);
};