403 on Cloudfront distibution with multiple S3 origins

0

I have a cloudfront distuibution that I server static website content from an S3 bucket on. I have created another S3 bucket that I am storing images on. The S3 bucket has a nested folder structure similar to: "foos/bars/image.png". I added the image bucket as another origin to the cloudfront distribution and added the path "images/upload/" in the behaviours, however I keep getting 403s when I navigate to "https://cloudfrontdomain.com/images/upload/foos/bars/image.png". Out of frustration I tried setting the path in the behaviour to "" to see if that would work and accessing "https://cloudfrontdomain.com/foos/bars/image.png" worked and successfully returned my image. Obviously this isn't a viable soution but demonostrates my permissions must be somewhat right. Any help would be appreciated

connor
已提问 1 个月前355 查看次数
1 回答
1
已接受的回答

Hello.

CloudFront adds the requested path to access your origin.
In other words, in this case, a request is sent to S3 with the path "images/upload/image.png" attached to access S3.
Therefore, if there is no object in "images/upload/image.png" in the S3 bucket, an error will occur.
So, I think the problem can be solved by placing the image file in "images/upload/" of the S3 bucket.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesOriginPath

If you want CloudFront to request your content from a directory in your origin, enter the directory path, beginning with a slash (/). CloudFront appends the directory path to the value of Origin domain, for example, cf-origin.example.com/production/images. Do not add a slash (/) at the end of the path.

profile picture
专家
已回答 1 个月前
profile picture
专家
已审核 1 个月前
  • This worked thank you! I didn't realise the same logic applied with the path in the behavoiurs as the origins

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则