I am trying to host static websites on S3. I know how to do it using S3 buckets (Link)
Question:
Can I do it using S3 folder instead of S3 bucket? So that I don't have to create a new bucket when I want to host a static site and simply host it by creating a new folder in the same bucket.
If you want to point a custom domain name to the site you are hosting in S3, then the bucket name must match the domain name, so you can't have multiple sites with multiple domains in the same bucket. Also, the static site hosting settings are at the bucket level not the "folder" level. NOTE: There is actually no such thing as a folder in S3, just key prefixes.
Related
I have a static website hosted on S3 with CloudFront.
The bucket name is "www.domain.com" and it's a react website built with npm build.
I was wondering, for CloudFront to work with posts uploaded by the user, does the content need to be inside this bucket or can it be a different bucket called "domain-media", for example?
I'm not yet sure how this all works exactly.
I am using AWS S3 bucket for storing and displaying the user upload image files.
My website name is example.net and as I want to use cloudflare CDN and show the image url path as images.example.net (as I want to mask the S3 url).
I created a S3 bucket with name images.example.net and mapped the CNAME images.example.net.s3.us-east-1.amazonaws.com as images.
So I am able to access the images using url images.example.net/myPic.jpg
Recently I got a new domain example.com (only the extension is different), and now I want to use the same S3 bucket example.net to store the files and the url needs to shown as images.example.com/myPic.jpg
If I create a new S3 bucket images.example.com , then I can do it, but I want to use the existing one only.
Is there any method to configure in cloudflare for that ?
Can I do it without creating a new bucket named images.example.com ?
If you're using virtual hosting then you're limited to a single domain per bucket by using the domain as the bucket name.
The only options available to you are:
Create a second S3 bucket with your other domain name as the CNAME
Create a CloudFront distribution in front of your S3 bucket and specify both domains as alternative domain names. Then on CloudFlare use the CloudFront CNAME. Disable all caching to allow CloudFlare to handle all the CDN functionality.
Obviously neither are ideal for your scenario, however these are the options available at this time.
Is it possible to host multiple subdomains from a single bucket folders?
Example -
Lets assume bucketname is my aws s3 bucket.
To access the site url is - http://bucketname.s3.amazonaws.com.
Now lets assume i have 5 folders inside it - a,b,c,d & e.
Can i create subdomains pointing to their respective folders inside the s3 bucket. Like -
http://a.bucketname.s3.amazonaws.com site works from folder a of the bucket
http://b.bucketname.s3.amazonaws.com site works from folder b of the bucket
http://c.bucketname.s3.amazonaws.com site works from folder c of the bucket
and so on.
Is it possible ?
Amazon S3 alone cannot do what you ask for.
The URL will point to only one bucket.
Typically, however, people want a Custom URL to point to content. For example, you could point mycompanyname.com to Amazon S3. This involves:
Owning the domain name
Creating a bucket with a name that matches the domain name (thus, you'd need one bucket per domain/subdomain)
Configuring the DNS entry (in Amazon Route 53 or your own DNS provider) to with a CNAME that points to the S3 bucket
Alternatively, behaviours can be configured in Amazon CloudFront that can present content from various back-ends.
Naming conventions for bucket URL are fixed by AWS. You cannot change to subdomain URL. You can use CloudFront to host it in your own domain or it can host under *.cloudfront.net.
Subdomain for cloudfront is also random. Will look like the following.
d3v7q0dqls688r.cloudfront.net
Hope it helps.
I've been using AWS_CLOUDFRONT_DOMAIN = 'media.example.com'
One consequence is that I have database records of image urls which have the above domain name enbeded such as http://media.example.com/media/blog_image_web/2016-07-01/702ef913-ddeb-4880-a715-397ce7b9efd7.jpg
Now I'd like to stop using cloudfront and just want to server from S3.
Problem is S3 url looks like http://my.bucketname.s3.amazonaws.com/media/blog_image_web/2016-07-01/702ef913-ddeb-4880-a715-397ce7b9efd7.jpg for the same image file..
I can update the database by replacing
http://media.example.com/ to http://my.bucketname.s3.amazonaws.com/
However, it would be much better if I can just keep using http://media.example.com/ whether I use cloudfront or not (or I could move my bucket later).
How can I use a custom domain to access s3 objects?
You can assign a custom domain to point to an Amazon S3 bucket.
The basic steps are:
Create an S3 bucket with a name equal to the domain name (eg media.example.com)
Activate Static Website Hosting on the bucket
Create an A record in Route 53 for media.example.com with Alias = YES and point it to your S3 website endpoint
See documentation: Example: Setting Up a Static Website Using a Custom Domain
Is there any way on AWS S3 to host a website inside a specific folder ?
Example: http://my-bucket.s3-website-us-west-2.amazonaws.com/ pointing to /build folder.
Thanks in advance,
Pierre
Yes. You can.
If you integrate with AWS CloudFront, you will set the CloudFront distribution's Origin Domain Name as your S3 Bucket's Static Website Hosting Endpoint and the Origin Path to the index.html file inside the build folder.
No, the website must be in a bucket, and the bucket must match the domain. Files within the website can live in folders, but the root must be at the bucket's top level.