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

Qis*_*han 5 amazon-s3 amazon-web-services

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

问题是,其他一些网站链接了我的图片/视频,这大大增加了s3的流量使用,当然还增加了支付账单.

我知道在某些情况下人们使用referer标题禁止外部网站链接.但在这种情况下,图片/视频直接从s3出来,而不是我的域名.

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

Abh*_*rma 5

您可以使用类似于以下内容的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/*"
                    ]
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

有关详细说明,请参见:http : //docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html