CNAME with S3 buckets
In the past S3 supported FQDN bucket names - i.e. exactly what you needed. Where FQDN = Fully Qualified Domain Name, i.e. full host name like static.mypage.com. The problem is that this only works with HTTP and not with HTTPS because there is no way to make S3 use a SSL certificate with your bucket name / host name (static.mypage.com).
You can still do it if you're happy with HTTP-only traffic. Simply create a
static.mypage.com CNAME at your registrar pointing to
s3.eu-west-1.amazonaws.com. S3 will recognise the
Host: header in the request and look into the right S3 bucket. Provided that the objects in the bucket are publicly accessible the URL http://static.mypage.com/pics/one.jpg should work just fine.
However as soon as you access the same over HTTPS you will get a SSL Certificate Validation error because the hostname in the S3 certificate *.s3.eu-west-1.amazonaws.com won't match the expected static.mysite.com.
The solution is CloudFront which can sit in front of your S3 and handle the right SSL certificate for it:
- create a free SSL certificate for static.mysite.com in Amazon Certificate Manager (or upload your 3rd party issued SSL cert to ACM).
- set up a CloudFront distribution, attach the SSL cert to it
- configure the CloudFront distribution to use your S3 bucket as the Origin
- configure a static.mysite.com CNAME at your DNS provider to point to the CF distribution name, e.g. d123456abcdef.cloudfront.net
- with that your desired URL https://static.mypage.com/pics/one.jpg should finally work.
Also have a look at Routing traffic to a website that is hosted in an Amazon S3 bucket.
Hope that helps :)