Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

AWS S3でStatic website hostingする際のReferer制御

More than 1 year has passed since last update.

実現すること

AWS S3でバケットをStatic website hostingする際に

  • index.htmlのみ公開
  • それ以外のリソースはRefererでアクセス制御

します

やりかた

S3のバケットの
アクセス制限/バケットポリシー
にて以下を記載します

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Allow all to index.html",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::${S3_BUCKET_NAME}/index.html"
        },
        {
            "Sid": "Allow all from own domain",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::${S3_BUCKET_NAME}/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": "https://${S3_BUCKET_NAME}.s3-ap-northeast-1.amazonaws.com/*"
                }
            }
        }
    ]
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away