Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CNAME to s3 bucket amazon

Tags:

I would like to use a subdomain instead of the direct url to my s3 bucket at amazon.com. So instead of downloading images via an url like http://bucket-images.s3-eu-west-1.amazonaws.com/path/to/image.pngI would like to use http://assets.domain.com/path/to/image.png. I tried setting a CNAME like this:

CNAME   assets   domain.com    bucket-images.s3-eu-west-1.amazonaws.com 

But after setting this CNAME I receive such error from amazon, when I visit the domain:

<Error>     <Code>NoSuchBucket</Code>     <Message>The specified bucket does not exist</Message>     <BucketName>assets.domain.com</BucketName>     <RequestId>45646DFSDFSFASDF</RequestId>     <HostId>         dfasdcvcvd546456454ds5fasdf4ad5f64asdfasdfccdfgvggtg     </HostId> </Error> 

Over here they're telling to change the bucketname: https://forums.aws.amazon.com/message.jspa?messageID=237562 But that doesn't make sense. I worked on a project earlier, who used a bucketname totally different from the subdomain. So there has to be a way... Anyone who can help me out?

like image 580
Erik van de Ven Avatar asked Dec 16 '15 15:12

Erik van de Ven


People also ask

How do I point Route 53 to S3?

To route traffic to an S3 bucketSign in to the AWS Management Console and open the Route 53 console at https://console.aws.amazon.com/route53/ . In the navigation pane, choose Hosted zones. Choose the name of the hosted zone that has the domain name that you want to use to route traffic to your S3 bucket.

What is a Cname in AWS?

In CloudFront, an alternate domain name, also known as a CNAME, lets you use your own domain name (for example, www.example.com) in your files' URLs instead of using the domain name that CloudFront assigns to your distribution.


1 Answers

For S3 you need the CNAME and bucket name to match:

The bucket name must be the same as the CNAME. So http://images.johnsmith.net/filename would be the same as http://images.johnsmith.net.s3.amazonaws.com/filename if a CNAME were created to map images.johnsmith.net to images.johnsmith.net.s3.amazonaws.com

So in your specific example you need to name the bucket assets.domain.com.

http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#VirtualHostingCustomURLs

If you need more flexibility, you can create a CloudFront distribution for your S3 bucket and assign a CNAME to your CloudFront distribution.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html

like image 96
Samuel Neff Avatar answered Sep 19 '22 23:09

Samuel Neff