Amazon s3 AWS S3不一致地提供CORS标头
我正在使用AWS S3,我已经将我的Bucket配置为使用CORS:Amazon s3 AWS S3不一致地提供CORS标头,amazon-s3,cors,Amazon S3,Cors,我正在使用AWS S3,我已经将我的Bucket配置为使用CORS: <?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET&l
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我尝试添加
*
和ETAG
,每次更改都会清除缓存,但没有效果。我很困惑。为什么标题没有通过?它并不总是返回CORs标题,似乎您需要提供一个原始标题,但您并不总是这样做
要使其一致并始终返回CORs标头,您需要添加一个lambda函数:
'use strict';
// If the response lacks a Vary: header, fix it in a CloudFront Origin Response trigger.
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
if (!headers['vary'])
{
headers['vary'] = [
{ key: 'Vary', value: 'Access-Control-Request-Headers' },
{ key: 'Vary', value: 'Access-Control-Request-Method' },
{ key: 'Vary', value: 'Origin' },
];
}
callback(null, response);
};
在此处查看完整答案和更多详细信息:尝试此解决方法,看看我的理论是否有效:设置对象元数据(当您上载时,或稍后在控制台中)以返回对象的
缓存控制:无缓存。清除浏览器缓存,然后进行测试。听起来很奇怪,我相信这是我以前见过的S3的设计问题。
'use strict';
// If the response lacks a Vary: header, fix it in a CloudFront Origin Response trigger.
exports.handler = (event, context, callback) => {
const response = event.Records[0].cf.response;
const headers = response.headers;
if (!headers['vary'])
{
headers['vary'] = [
{ key: 'Vary', value: 'Access-Control-Request-Headers' },
{ key: 'Vary', value: 'Access-Control-Request-Method' },
{ key: 'Vary', value: 'Origin' },
];
}
callback(null, response);
};