AWS S3 : Prevent Hotlinking policy
Problem :
Hosting a lot of photos or video files on AWS S3? Don't want other websites to link to your content or use your S3 as a free loader?
Solution :
Add new bucket policy to prevent hot linking. Go to the properties of the S3 bucket you want to prevent hot linking policy and click on the Add Bucket Policy button.
A modal box will appear and enter this policy :
{
"Version": "2008-10-17",
"Id": "preventHotLinking",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-s3-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://yourwebsitename.com/*",
"http://www.yourwebsitename.com/*"
]
}
}
}
]
}
NOTE : Change your-s3-bucket and yourwebsitename.com to yours.
Reference :
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
See also : WARNING: UNPROTECTED PRIVATE KEY FILE! error message
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.4k Golang : How to check if a string starts or ends with certain characters or words?
+6.4k Golang : Gorrila mux.Vars() function example
+16.1k Golang : How to tell if a file is compressed either gzip or zip ?
+6.2k Golang : Levenshtein distance example
+9.2k Golang : Channels and buffered channels examples
+6.8k Golang : Gorrila set route name and get the current route name
+6.1k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+27k Golang : Change a file last modified date and time
+27k Get file path of temporary file in Go
+8k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+4.9k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+8.6k Golang : Read file with ioutil