How to Prevent Hotlinking on Amazon S3 Storage

October 11th, 2011 by Regaz

It you try to Googling around you will find than at this time is not easy to Catching Up this Solution…
Sometime get Complicate to get some Big Fish on the WWW… But some time get Easy ;)
This will work on Every Os: Linux, Windows, Mac OS X and even in Unix :))

  1. Login in the Amazon AWS Console
    Select Amazon S3 from Drop Down list Click “Sign in the AWS Console”
    Insert your Credentials
  2. Amazon S3 > Properties > Edit Bucket policy
    Insert: (Substitute only YOUR-BUCKET-NAME and your-domain-name)
    {
    "Version":"2008-10-17",
    "Id":"",
    "Statement":[{
    "Sid":"Allow in my domains",
    "Effect":"Allow",
    "Principal":{
    "AWS":"*"
    },
    "Action":"s3:GetObject",
    "Resource":"arn:aws:s3:::YOUR-BUCKET-NAME/*",
    "Condition":{
    "StringLike":{
    "aws:Referer":["http://your-domain-name/*",
    "http://www.your-domain-name/*"
    ]
    }
    }
    },
    {
    "Sid":"Give not access if referer is no my sites",
    "Effect":"Deny",
    "Principal":{
    "AWS":"*"
    },
    "Action":"s3:GetObject",
    "Resource":"arn:aws:s3:::YOUR-BUCKET-NAME/*",
    "Condition":{
    "StringNotLike":{
    "aws:Referer":["http://your-domain-name/*",
    "http://www.your-domain-name/*"
    ]
    }
    }
    }
    ]
    }

    Save

  3. Test Properly If the Bucket Policy Effectively and Definitely Prevent Hotlinking
    Herein:
    Joomla Website Development
    Amazon AWS S3, Amazon AWS S3 Buckup, Amazon AWS Cloud

    Drupal Website Development

(Visited 35 times, 1 visits today)

Tags: , , ,


4 Responses to “How to Prevent Hotlinking on Amazon S3 Storage”

  1. Anonymous says:

    Hello thanks for the tips but one problem is I am using my own domain name by using CNAME. So instead of http://myBucketName.s3.amazonaws.com/foldername/yourMediaName I am using http://s.mydomainame.com/fooldername/yourMediaName means I have created a s CNAME and pointed to myBucketName.s3.amazonaws.com and in this situation how can I prevent hot link? Thanks in advance.

  2. Hi, thanks for commenting :)

    What the reason to introduce a CNAME in s3 linking?
    You can simply use your Original s3 Address…
    Not?!

    After you can Simply Authorize your CNAME address
    like any other URL…
    I mean you can make a Policy to Authorize your s.mydomainame.com like any other URL to use the S3 bucket.

    Let me know.
    Cheers
    Davide

  3. Anonymous says:

    “What the reason to introduce a CNAME in s3 linking?
    You can simply use your Original s3 Address…
    Not?!”

    It's concidered good practice to always link from your own domain. It's supposed to bring (keep) better SEO ranking and your website is trusted better because it all (seems to) come from the same domain!