Multiple subdomains for Amazon S3 Bucket? - amazon-s3

We are white labelling site so that mysite.com and site.com and site2.com all share the same code base but different front end UI. They use a lot of the same images, including product images, which are hosted on Amazon S3. The s3 bucket name is based off site.com such that the host is:
https://siteDOTcom-new.s3.amazonaws.com/
Now, we don't care what the Amazon S3 url looks like but some clients do, so we're trying to figure out how to do it. We've tried CNAMEs but that didn't work out. Is it possible to have multiple subdomain aliases for the same S3 bucket?

You should look into Amazon Cloudfront for two reasons:
It would allow you to point to the same s3 buckets with different URLs (e.g. http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html)
As a CDN, it will give better downloading speeds for people using your site

Related

Hosting multiple S3 origins under one CloudFront distribution

Is it possible to host multiple S3 origins under the same CloudFront distribution? Let's say I have bucket A and bucket B which both host static websites--could I add them both as origins to a distribution, and specify a path e.g. /alternate for the origin from bucket B so that visiting http://<distribution>/ took you to the website hosted by bucket A and visiting http://<distribution>/alternate brought you to the one hosted by bucket B? From what I've read so far it seems possible to have multiple origins, not necessarily multiple S3 origins.
You can add multiple S3 origins to a CloudFront distribution
However, behaviors are locked to a specific origin. Behavior controls the path. So, if /static is used by Origin A/S3 A, you can't have /static go to /Origin B/S3 B
Someone suggested using multiple CloudFronts with the same CNAME. That does not work either. CloudFront will not allow the same CNAME to be used in multiple distributions.
Academically speaking, this may be possible through LambdaEdge or some other external process that is checking S3 A, and if it is unavailable (say - under maintenance while new code being pushed), it can go and update CF Behavior for /static to Origin B/S3 B.
I wish AWS came up with a more elegant solution to this use case. Like allowing same CNAME in multiple distributions, or providing some kind of R53 integration with S3 buckets (never tried putting two different S3 buckets behind R53 .. probably will not work because the host header would change)
You can attach a Lambda function as a trigger to intercept CloudFront's routing. The implementation is quite involved; but would permit your specific use case.
Example Implementation:
https://aws.amazon.com/blogs/networking-and-content-delivery/dynamically-route-viewer-requests-to-any-origin-using-lambdaedge/
Lambda#Edge:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html

How to point Amazon S3 bucket to test subdomain like images.develop.example.com

Currently I'm using Amazon S3 bucket for my website like images.example.com .Today I also built a test subdomain for development purposes and it is served in develop.example.com
Now I want to use Amazon S3 bucket like develop.images.example.com or images.develop.example.com (I don't know which of them is correct)
Is it possible according to S3 restrictions?
Because Amazon says: You must have same bucket name with your subdomain. So I was create a bucket like images.example.com
and my cname record is: images.example.com.s3-website.eu-west-2.amazonaws.com
My webserver is Apache and runs on Ubuntu
How can reach to my images on my development subdomain?
Should I create a new cname record?
Should I do something on my virtual host file?
or what?
To share static content from develop.images.example.com:
Create an Amazon S3 bucket called develop.images.example.com
Turn on static website hosting
Create a Route 53 A record for develop.images.example.com with Alias=YES and point it to your S3 bucket
This is the same process as you would have followed for images.example.com.

S3, from deep link to sub domain (bucket)

I would like to redirect a link as www.example.com/test to a bucket called test.example.com on S3. As far as I know, Apache has a file called .htaccess that does the trick. I'm able to redirect from test.example.com to a bucket on S3, but I don't know how to do it with the deep link thing. Is that possible?
It seems there is no way to accomplish that. I have seen many posts describing amazon s3 as a "very simple container". I solved my problem by creating a folder named test on the main bucket (www.example.com) with a html page redirecting to the actual bucket test.example.com. The best solution is to move to an apache container service, but for the moment I want to keep it simple.

How do I map multiple domains to the same bucket on Amazon S3?

Is it possible to do that? I need to be able to access mydomain.com by typing in my-domain.com in the address bar of the browser?
Now I added a DNS entry:
my-domain.com CNAME mydomain.com
But this doesn't seem to work. I get an 404 not found error.
You can only map a single domain to your S3 bucket. However you could use Cloudfront to do this.
See my answer to another similar question for more information.
We had the same issue and basically I set our CI to publish to two S3 buckets on release. Not ideal but keeps you clear from resetting caches in CloudFront on publish for the short term.

Using amazon s3, upload files using their servers but URL should appear to be from mine

Is it possible to upload files to amazon S3, using their servers (i.e. my server shouldn't be used in the upload process)?
I also want the URL to appear to be uploading to my server, is this possible?
Look here for instructions on how to setup your CNAME record so that one of your subdomains can be an alias for an Amazon S3 bucket.
Depending on your needs, you might not want "s3.amazonaws.com" to appear on your web site or service. For example, if you host your web site's images on Amazon S3, you might prefer http://images.johnsmith.net/ to http://johnsmith-images.s3.amazonaws.com/