LoginSignup
3
3

More than 5 years have passed since last update.

S3でWebSite Hostingした時にIPアドレスで制限をかける

Posted at

S3にstaticなHTMLをおいて、それを特定のIPからのみ見えるようにする方法。

いつも迷ってしまうので備忘録で書いておく。

Access Control List は変更する必要なし。( List objects の everyone も - のまま)
バケットの中のファイルもPrivateな設定のままでOK。

{
    "Version": "2012-10-17",
    "Id": "Policy1551163444222",
    "Statement": [
        {
            "Sid": "Stmt1551163442413",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::[Bucket Name]/*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "[IP]"
                }
            }
        },
        {
            "Sid": "Stmt1551164678580",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::[Bucket Name]/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": "[IP]"
                }
            }
        }
    ]
}

いつも思ったように動かなくてもがくのは Resource 部分の最後に /* をつけ忘れて、ファイル見れないじゃん…ってなる。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3