S3 Static Website directory index redirect with CloudFront - amazon-s3

With an S3 static site, I am able to hit /directory and it will serve up the index.html file inside the directory. Once I add the S3 bucket as a CloudFront origin, I instead get an Access Denied message.
How can I replicate this S3 functionality in CloudFront?

The fix was to setup S3 static site hosting and use CloudFront to point to it as a remote origin website instead of an S3 bucket.

Related

Cloufront should always append path for s3 bucket

I have a Cloudfront service which points to an index.html file in a S3 bucket.
Calling the Cloudfront URL is rendering the application which is correct.
I now want to use a custom "path" that gets appended to the Cloudfront.
So instead https://asdf.cloudfront.net/ I want to use https://asdf.cloudfront.net/my-app/ to point to my S3 bucket.
Is this possible with Cloudfront or do I have to move my s3 bucket content into a folder and then point to it?

How to host website in S3 and CloudFront?

I am trying to host my Angular website using CloudFront, S3, and Amazon EC2
instances. I am creating a bucket for e.g. bucket_name and creating 3 folders in it naming:-
1. example
2. login
3. logout
And my URL is:-
1. abc.com/example/
2. abc.com/example/login
3. abc.com/example/logout
But when I host my website I am able to access abc.com/example/ but the issue I am facing is that when I tried to access login and logout URL I am getting an error "404 not found". Because it is trying to locate index.html in the example folder of the S3 bucket like in this way example/login/index.html and EC2 instance is for API calls.
To host your site on S3 bucket and aws CloudFront you must include your parent file index.html in S3 bucket and after this you need to configure static website hosting under properties of S3 bucket. Set these fields as use this bucket to host website then enter index document index.html this file must be in S3 bucket, and save this.
Next step you can edit public access of this bucket, if you want this site accessible outside world then turn off block public access under Permissions tab of S3 bucket.
Later, to host this using CloudFront you need to create CloudFront distribution, and set Origin Domain name = Your S3 bucket name and Default Root Object to your parent index.html file (which is stored in s3 bucket) and save this CloudFront distribution, now check the Domain name URL on browser, it should work fine.
After completing this you can setup your EC2 instance for back-end API calls as per your needs.
Try to keep pages like login.html and logout.html. That should work.

Attach S3 bucket to URL endpoint

How can I attach an S3 bucket to an URL on my site. I tried but could not get it to work.
For instance my URL is:
mysite.com/media
And my S3 bucket should be linked directly to the above URL?
You're going to want to use CloudFront in front of S3. This will allow you to use your domain and serve content from S3.
Check out Using CloudFront with Amazon S3 for details on how to do it.

Resolve S3 static page from custom path with CloudFront

I've got an S3 bucket configured to host a static website, and if I browse to the bucket URL it shows the index.html file. I also have a CloudFront distribution to show another S3 bucket under a custom domain. Is there any chance I could configure CloudFront to serve one bucket from the root and another from a custom path? So:
mydomain.com -> bucket1/index.html
mydomain.come/some-path -> bucket2/index.html
I already created an origin for the bucket and set up a path pattern for it and some-path, but I'm getting 403 Forbidden, even though if I browse to the origin directly I can see the webpage.
This configuration works fine, but it requires that the object in bucket2 be located at some-path/index.html inside bucket2.
The path pattern you configured in the cache behavior is still part of the request path, so it is forwarded to the origin.
CloudFront does not support removing part of the request path before forwarding the request to the origin.

How to configure amazon cloudfront to block some S3 bucket files access?

On S3 we have all files as private. Users can't load any file through S3 link. But they are all public through cloudfront link.
How can i restrict access to ./restricted.txt? (only users who use signed URL link can see that file through cloudfront link), ./not_restricted.txt must be public the same time.
How i did that.
I have created /public & /private folders on s3, separated my private/public files, created cloudfront origin that point to /public. So all my S3 files which are in /public folder are public and i can load them using link without public prefix /img1.jpg istead /public/img1.jpg, because cloudfront thinks about /public as a root folder.
Now all my files that are in /private or any other place above /public folder are private through either S3 and cloudfront links.
But i don't know how to create signed URL for /private/restricted.txt file that will have cloudfront path. I can create signed url which use S3 path, but i need to have cloudfront link.
Thanks in advance.
Within CloudFront there is the concept of "Cache Behaviours". Based on URL paths these allow you to modify caching behaviour, including the requirement to use Signed URL/Cookies.
If I understand it you want to:
Maintain your private S3 bucket
Maintain some public paths through CloudFront (/public)
Have a private path through CloudFront (/private)
This could be done by simply adding a new Cache Behaviour within your CloudFront distribution and setting Restrict Viewer Access (Use Signed URLs or Signed Cookies) to Yes. For instance:
So to reiterate, the easiest way to achieve this would be
Use OAI between S3 and CloudFront
Have a single CloudFront distribution pointing to your S3 bucket (root, rather than /public)
Create a new cache behaviour which enables signed URLs for /private
If this doesn't answer your question, for instance if you need to maintain paths and can't use /public and /private in the URL schema itself, let me know with a comment and I can try to elaborate. Thanks!