I host all the images used on blog post on Amazon S3. As Amazon S3 bandwidth cost me money 💰, I am paranoid and afraid someone is hotlinking my image on their server and keep refreshing their page 24/7 to eat up my bandwidth cost 😫.

No worries, bucket policy to the rescue! Head over to the bucket containing your image, and click “Edit bucket policy”. edit bucket policy

Paste this bucket policy end edit a little :

Edit the “Resource” key and replace arn:aws:s3:::littlefoximage/* with your s3 bucket name such as arn:aws:s3:::your_s3_bucket_name/* . If you want to specify a folder location instead of all folders/files, replace the “*” at the end with the path to your folders/files.

Edit the “aws:Referer” key and add your website address(es) here, you can use “*” wildcard in front or end of the domain name.

Click “Save” when you are done editing.

Now when someone hotlink your image on unauthorized domain, they will be greeted with this error message :
access denied

Now you can sleep soundly at night without worrying someone stealing your S3 bandwidth 😝