Website hosting in specific folder on AWS S3 - amazon-web-services

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.

Related

Multiple websites in the same S3 bucket

I am trying to host multiple websites with similar subdomains in the same S3 bucket under different folders with a cloudfront distribution that redirects to each folder.
Suppose my bucket is example.com and I want to host my angular website at sub1.example.com and another one at sub2.example.com. I have created folders for each of them in the bucket named sub1 and sub2. I have also created cloudfront distributions with the origin name points to the S3 bucket and added the origin path to the corresponding folder.
After doing this, if I try to go to sub1.example.com it works fine. But if I try sub1.example.com/home I get a 404 page with Code: NoSuchKey. I think this is because S3 is trying to look for sub1/home in the bucket rather than serving the angular file in the sub1 folder.
Is this something that can corrected? I need to do this with a single S3 bucket.
I've managed to fix the issue by following these instructions. I was able to fix the issue after adding Default Root Object when creating the cloudfront distribution and adding custom error responses in the cloudfront distribution that redirects 404 and 403 error codes to index.html.

AWS S3 sending download.txt file

I'm setting up an S3 bucket behind CloudFront that is meant to serve static assets. My problem is doing a / on any directory with no file name will have the browser download a download.txt with 0 bytes. I have my S3 bucket setup for Static Website Hosting and is pubic, so I'm able to access my assets.
https://s3-bucket.domain.com/path/to/file.jpg -> get asset, working
https://s3-bucket.domain.com/path/to/file-bad-name -> Error status 403, working. Renders error.html from S3.
https://s3-bucket.domain.com/path/to/ -> sends download.txt, not working
How do I configure #3 to not send a download.txt and render an error page instead?
There are few things happening there.
You need to map it to new origin if you want to point the path to an S3 object.
Your pattern is not having priority in CloudFront.
If you fix one of the above or both, then it should work as expected.
I have my S3 bucket setup for Static Website Hosting and is pubic
...but you selected the bucket from the dropdown list when defining the origin... yes?
You need to configure the origin domain name to use the web site hosting endpoint for the bucket.
When you configure your CloudFront distribution, for the origin, enter the Amazon S3 static website hosting endpoint for your bucket. This value appears in the Amazon S3 console, on the Properties page under Static Website Hosting. For example: http://bucket-name.s3-website-us-west-2.amazonaws.com
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DownloadDistS3AndCustomOrigins.html#concept_S3Origin_website
If you don't do this, and you created folders in the bucket using the S3 console, then what you are currently observing is the expected behavior, a side effect of the way the console creates those imaginary folders.

Hosting a Static website in S3 Bucket Folder

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.

Redirect index.html to root with AWS s3 bucket (no htaccess)

I have a simple, static webpage hosted in a AWS S3 bucket. S3 buckets do not support htaccess, as this is apparently an Apache feature.
I would like to redirect all www.example.com/index.html to simply www.example.com. Is there a way I can do this from my DNS management, or some other way I don't know about?
Thanks.
You can do this by enabling Static Web Site hosting feature in your S3 bucket properties. index.html is the default index document at the moment, so it will just work out of the box for you.
See http://docs.aws.amazon.com/AmazonS3/latest/dev/IndexDocumentSupport.html for more detail.
Enabling Websitehosting for your S3 Bucket will do the trick. Doing so allows you to specify an index an error document.
see http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html

Host index.html in subfolders of S3 Bucket

Static website hosting is working in the root directory, but this is not working for me:
my.bucket/index.html
my.bucket/subfolder/index.html
https://s3-eu-west-1.amazonaws.com/my.bucket works as expected
https://s3-eu-west-1.amazonaws.com/my.bucket/subfolder doesn't work (Access Denied)
Is this possible?
There are (at least) three ways to access a static website hosted in AWS.
The S3 bucket name
The CDN name. (which is what the "host a static website" wizard tells you to use)
The "Static website hosting endpoint" which is listed on the S3 bucket management page
Only the "static website hosting endpoint" filters incoming requests to give Apache like behaviour; S3 is a RESTful API for storing files with no concept of subfolders.
If you have used the wizard, there is "Manage file in S3" in tiny text at the bottom left of the screen, which will open up the correct page in the console for you, then click the 'properties' button.
You need to modify the permissions of the sub-folder as well to make it publicly accessible.