我想使用S3对象元数据和DB(或某些远程服务)中的一些角色数据来保护Cloudfront响应,这是当前用户的特定.我想我应该viewer-response在这里使用事件,以便一起访问S3数据和用户数据.我尝试设置status和statusDescription在response对象中,但它不适用于viewer-response事件,适用于所有其他事件.设置标题仍然有效.
exports.handler = async (event) => {
const response = event.Records[0].cf.response;
const request = event.Records[0].cf.request;
const isUserAllowed = await allowedByTokenAndDb(request);
const isS3ObjectAllowed = response.headers['x-amz-meta-isSecure'][0].value === 'true';
if (!isUserAllowed || !isS3ObjectAllowed) {
response.status = '403'; // does not work
response.statusDescription = 'Nothing';
}
response.headers['X-Powered-By'] = [{ // works, header will be added
key: 'X-Powered-By',
value: 'lol',
}]
return response;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让viewer-response返回另一个状态?AWS文档并未说明它是否可行.也许有另一种解决方案?