dev.e.loper
dev.e.loper

Reputation: 36034

Enabling Website Hosting and renaming existing S3 bucket in order to get the right URL

Currently, I have an S3 bucket set up that has URL:

https://s3-us-west-2.amazonaws.com/<BucketName>/<Filename>

What I would like to do is to load the files from this bucket from:

https://images.mysite.com/<Filename>

This AWS documentation page says:

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.

Upvotes: 0

Views: 410

Answers (2)

Michael Bissell
Michael Bissell

Reputation: 1208

If you do not want to change the bucket name then you need to proxy the resource either through Amazon Cloudfront (which will require cache invalidation when you make changes to your bucket content) or you could spin up a small EC2 instance with an Apache Web Proxy

ServerName yourdomain.com
<Proxy *>
  Order allow,deny
  Allow from all
  SetEnv proxy-chain-auth
</Proxy>

SSLProxyEngine On
ProxyRequests On
ProxyPreserveHost Off
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

ProxyPass / http://your-bucket.s3-website-us-west-2.amazonaws.com/
ProxyPassReverse / http://your-bucket.s3-website-us-west-2.amazonaws.com/

Note the ProxyPreserveHost Off directive, which means the s3 name is still delivered to the target. Disadvantage to Apache proxy is that it becomes a bottleneck, but you can use t2.smalls in the free tier and then add them to an autoscale group

Upvotes: 0

E.J. Brennan
E.J. Brennan

Reputation: 46839

If you don't actually want to run a website from your s3 bucket, but instead are just looking to serve images with a custom domain (which it seems like from your question), then you could use a custom domain with cloudfront distribution and you won't have to move or rename anything (and the old links will continue to still work):

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

Answers to your questions though:

  • Yes
  • No
  • The old links would no longer work, but the files themselves would not be lost.

Upvotes: 1

Related Questions