CNAME - s3 bucket amazon

I would like to use a subdomain instead of a direct url for my s3 bucket on amazon.com. So instead of uploading images via url like http://bucket-images.s3-eu-west-1.amazonaws.com/path/to/image.png , I would like to use http://assets.domain.com/path/to/image.png . I tried to set CNAME as follows:

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

But after installing this CNAME, I get this 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> 

Here they report a change to the name bucket: https://forums.aws.amazon.com/message.jspa?messageID=237562 But that doesn't make sense. I used to work on a project that used a bucket name that is completely different from the subdomain. So there has to be a way ... Anyone who can help me?

+5
source share
2 answers

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

The bucket name must match the name CNAME. So, http://images.johnsmith.net/filename will be the same as http://images.johnsmith.net.s3.amazonaws.com/filename if CNAME was created to display images.johnsmith.net in images.johnsmith .net.s3.amazonaws.com

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

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 CNAME to your CloudFront distribution.

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

+9
source

Additional information for @Samuel Neff:

Just remember your AWS S3 bucket name just like your CNAME Cloudflare record. Otherwise it will not work.

Here I tried and worked for me:

The old https://s3-eu-west-2.amazonaws.com/cdn.domain.com at http://cdn.domain.com

0
source

Source: https://habr.com/ru/post/1238396/


All Articles