title: Amazon S3 Bucket policy, allow only one domain to access files
body: <p>I have a S3 bucket with a file in it. I only want a certain domain to be able to access the file. I have tried a few policies on the bucket but all are not working, this one is from the <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html" rel="noreferrer">AWS documentation</a>.</p>
  
  <pre><code>{
      "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:::my-bucket-name/*",
              "Condition": {
                  "StringLike": {
                      "aws:Referer": [
                          "http://www.phpfiddle.org/*",
                          "http://phpfiddle.org/*"
                      ]
                  }
              }
          }
      ]
  }
  </code></pre>
  
  <p>To test the file, i have hosted a code on phpfiddle.org and have this code. But i am not able to access this file neither by directly accessing from the browser nor by the phpfiddle code.</p>
  
  <pre><code>&lt;?php 
      $myfile = file_get_contents("https://s3-us-west-2.amazonaws.com/my-bucket-name/some-file.txt");
      echo $myfile;
      ?&gt;
  </code></pre>
  
  <p>Here are the permissions for the file, the bucket itself also has the same permissions + the above policy. </p>
  
  <p><a href="https://i.stack.imgur.com/0l6QM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0l6QM.png" alt="enter image description here"></a></p>
  
  <p><strong>This is just an example link and not an actually working link.</strong></p>