S3/Cloudfront Access Denied

本文转载自:https://migueldavid.eu/cloud/s3cloudfront-access-denied/


So you finally listened the SEO guys who keep saying that the images on your website have to be fast and you decided to move them from your small cloud server to an AWS S3 bucket?
You managed to create the bucket and even enabled Cloudfront on that bucket so that the images (or other files) are not only in one region of AWS but everywhere in the world (well, every edgenode on AWSs Content Delivery Network). This will make sure that someone in Japan will see your site as fast as someone in Oregon, USA.
You then uploaded the files and changed your website code to point, not to your local server files but to the cloudfront URL (or S3 bucket URL), but when the moment of truth comes… The images are not showing up and when you go directly to the link of the image you get a nasty XML saying “Access Denied”.

The good news is that you are not the first person to go through this so the process of adding the permissions is straigh forward:

  1. Go to AWS S3 and click on your bucket
  2. Click on properties
  3. Click on Edit bucket policy
  4. Copy the following into the text box, replace examplebucket with your bucket name and you’re done

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"AddPerm",
      "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::examplebucket/*"]
    }
  ]
}

What are we doing here exactly? We are allowing everyone in the world to be able to get objects from your S3 bucket.
Don’t worry, no-one will have access to creating/deleting/changing your files, only to see all the files in that bucket (which should be the bucket with your publicly available web files anyway).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值