简体   繁体   English

仅允许在 AWS S3 中公开访问图像

[英]Allow public access for images only in AWS S3

I'm new to AWS and it make me confuse, it's hard to use.我是 AWS 新手,这让我很困惑,很难使用。 I have a web app, which use images from folder /images/ in bucket.我有一个 web 应用程序,它使用存储桶中 /images/ 文件夹中的图像。 I have other /mp4/ folder which save videos.我还有其他保存视频的 /mp4/ 文件夹。

Now I want public access to images folder only.现在我只想公开访问图像文件夹。 How do I write the permission policy?如何编写权限策略? I dont want people access my mp4 files by entering url.我不希望人们通过输入 url 来访问我的 mp4 文件。

Thank you for help谢谢你的帮助

This policy will allow public access to objects from the images/ folder in the my-bucket bucket:此策略将允许公开访问my-bucket存储桶中images/文件夹中的对象:

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Effect":"Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": [
        "arn:aws:s3:::my-bucket/images/*", 
        "arn:aws:s3:::my-bucket/other-folder/* "
      ]
    }
  ]
}

Before adding this policy, turn off S3 Block Public Access for the bucket (turn off the two options that mention Bucket Policy).添加此策略之前,请关闭存储桶的 S3 Block Public Access (关闭提及 Bucket Policy 的两个选项)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM