8

I need the following url

http://liangpai.s3.amazonaws.com/uploadImage/shareImage/2012-10/506dc1ef71dcf.png

showing as:

http://imgs.liangpai.me/uploadImage/shareImage/2012-10/506dc1ef71dcf.png

My S3 bucket name is “liangpai”. On Route 53, I created a new CNAME named “imgs”, the value I entered is “liangpai.s3.amazonaws.com”

After this I don’t see the S3 web link changes to my domain link.

Anything wrong here?

Thanks for your advice!

100calorie
  • 305
  • 3
  • 4
  • 7

3 Answers3

23

S3 CNAMEs require the bucket name to match the host name. If you want S3 to serve from imgs.langpai.me, you need to create a bucket named imgs.langpai.me. See the S3 documentation for more.

You could create a CloudFront distribution to answer to imgs.langpai.me (see CloudFront CNAME support) have it and forward requests to langpai.s3.amazonaws.com. This would, of course, also incur CloudFront charges.

willglynn
  • 11,210
  • 48
  • 40
6

Method 1 : S3 direct CNAME by bucket name

You can create a CNAME record by bucket name following these steps.

  1. Create a bucket name using the same name you will use for your dns entry. i.e. subdomain.mydomain.net

  2. Create a cname record for subdomain.mydomain.net to s3.amazonaws.com

  3. Set permissions on your bucket based on the access you plan to grant

Method 2 : Static Website on S3

If you are serving static content such as images, files, etc. you can use "Static Website Hosting" for your S3 bucket.

Select your bucket by clicking the bucket icon (enter image description here) and select the "properties" tab on the right and expand "Static Website Hosting". In the Static Website Hosting panel, select the radio button to "Enable website hosting" and set an index and error document. It this point, you will see an "Endpoint" name in this panel. Simple create a DNS CNAME record with the endpoint as the value. You can read the entire Amazon Walkthrough here.

enter image description here

Vyke
  • 3,099
  • 1
  • 17
  • 6
  • Hi @Vyke, can i point my subdomain called as "download.abc.com" to a bucket named download.abc.com? I haven't turned on static website hosting, cause it is simply used for downloading executables. Creating CName record for the same doesnt work-does this mean I ought to have configured it as static website for it to work- any ideas? Your answer on Method -1 says I need to point it s3.amazonaws.com- would it work if there are other buckets as well? – Jaya Jan 03 '15 at 00:46
  • 1
    Seems that just adding a CNAME to the Endpoint of the S3 bucket (even after you enable static website) does not work. As the results is: NoSuchBucket It seems that willglynn is correct in stating that you need to have the same bucket name as your CNAME record – Maksim Luzik Jul 28 '16 at 14:45
1

Try this

Using your own bucket CNAME:

echo S3::getAuthenticatedURL("s3bucket.mydomain.com", $uri, 3600, true);

but you putobject file check for read for Everyone premisssion type:

S3::ACL_PUBLIC_READ

$s3->putObjectFile($tmp, $bucketname , $path.$filename, S3::ACL_PUBLIC_READ)