amazon-s3 - 如何仅允许 aws s3 存储桶内容公开服务于某个域?

标签 amazon-s3 amazon-web-services

我正在使用 aws s3 来存储我的网站图片和视频内容。来自 s3 的文件链接直接输出到 html/php。

问题是其他一些网站链接了我的图片/视频,这大大增加了 s3 流量使用,当然也增加了工资单。

我知道在某些情况下人们使用引用 header 来禁止外部站点链接。但在这种情况下,图片/视频直接从 s3 出去,而不是我的域。

有人可以帮助实现这一目标吗?谢谢。

最佳答案

您可以使用 Amazon 存储桶策略,例如:

{
    "Version": "2012-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originated from www.example.com and example.com",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::examplebucket/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "http://www.example.com/*",
                        "http://example.com/*"
                    ]
                }
            }
        }
    ]
}

详细解释在:http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html

关于amazon-s3 - 如何仅允许 aws s3 存储桶内容公开服务于某个域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313781/

相关文章:

amazon-web-services - AWS Redis - 启用/禁用集群模式。它是如何分配流量的?

amazon-web-services - Alexa SSML 不播放

android - 将对象上传到 Amazon s3 时如何为其设置 ACL?

amazon-web-services - Cloudformation 存储桶策略 - "Statement is missing required element"

go - S3 以编程方式删除以换行符 (%0A) 结尾的文件?

java - 如何使用 Java 创建多语言 Alexa Skill?

python - 从列表中更新大量 dynamodb 项目的最佳方法

python - 返回过去 24 小时内修改过的 Amazon S3 存储桶中的所有 key

java - Spring AWS S3 : How to upload an image and get a URL which shows it rather than downloads it?

node.js - 无法从 Internet 访问 AWS 中使用端口 3000 的 NodeJs 应用程序