I'd like to allow anyone to play a video located in my s3 on my site as the src
on a <video>
tag but not allow people to use it as a src
on their site or to play the video directly by typing the url into the browser bar.
I don't want people doing this:
and I don't want the following HTML to appear on http://your-site.com but only on http://my-site.com:
<html>
<video src="https://s3.amazonaws.com/my-bucket/my-video.mp4"></video>
</html>
I've seen some SO links on this but I wanted to talk in code since I haven't been able to make these solutions work for me.
Here's my bucket policy that is currently NOT working:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"https://my-site.com/*"
]
}
}
}
}
Two questions:
- To test my bucket policy, I put the above HTML in a test file on my localhost and sure enough I can access the video by typing
http://localhost/test.html
. Why isn't my bucket policy preventing this? (I'd only want it to work fromhttp://my-site.com/test.html
) - To prevent people from inputing the s3 URL into the browser bar, I was thinking I need a separate solution from the bucket policy since it's not clear to me from the AWS documentation how to prevent direct access via the browser. I was thinking of hashing the url to make it hard to guess. Perhaps there are ways using the AWS bucket policy or other solutions though?
To be more clear, my files are stored on s3 but they are delivered by Amazon's CloudFront. So my CloudFront url src is currently media.my-site.com/my-video.mp4. The CNAME being media.my-site.com.
src
CloudFront url is currently something like thismedia.my-site.com/my-video.mp4
. Does that help explain better? I'll make this more clear in my question. – Virgymedia.my-site.com
is my CloudFront CNAME but I guess I can break offender's links but not my own by changing this CNAME regularly. I'll look into contacting AWS on this. – Virgy