我已经设置了带有S3源的CloudFront来服务来自S3的图像。现在添加Lamnda@Edge进行图像转换。它基于status代码(200或404)工作
但是回源的Cloudfront事件总是有status: '403'
以下是示例响应(来自event.Records[0].cf)
{
config: {
distributionDomainName: 'xxxx.cloudfront.net',
distributionId: 'xxxxx',
eventType: 'origin-response',
requestId: 'YVAViQDNbJcmgRlZFEWjxS2xF5balXwR-Kkv8PN4jXRO4hEPksOaJg=='
},
request: {
clientIp: '81.403.0.141',
headers: {
referer: [Array],
'x-forwarded-for': [Array],
'user-agent': [Array],
via: [Array],
pragma: [Array],
'accept-encoding': [Array],
host: [Array],
'cache-control': [Array]
},
method: 'GET',
origin: {
s3: [Object]
},
querystring: '',
uri: '/images/product/photo/photocell_white.webp'
},
response: {
headers: {
'x-amz-request-id': [Array],
'x-amz-id-2': [Array],
date: [Array],
server: [Array],
'content-type': [Array],
'transfer-encoding': [Array]
},
status: '403',
statusDescription: 'Forbidden'
}
} 我的S3存储桶是公开可写的(我知道这很危险,但只是为了让它正常工作)。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::stage.domain.com/*"
}
]
}在CloudFront中
Origin Domain Name : stage.domain.com.s3.amazonaws.com
Origin Path : /assets
Origin ID : S3-stage.domain.com这里出了什么问题?
Lambda函数:https://pastebin.com/raw/FNd59Tvn
发布于 2021-01-14 16:19:18
S3在设计上返回403。当访问用户没有权限访问s3:ListBucket时,s3返回403。
你可以找到更多的here
您需要将以下语句添加到您的保单中:
{
"Sid": "PublicListAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::stage.domain.com"
}警告
确保您了解授予公众列出s3存储桶中所有对象的能力的后果。
https://stackoverflow.com/questions/63497579
复制相似问题