Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you disable directory listing in AWS CloudFront?

I have an S3 bucket. When accessing its root URL via https://s3.amazonaws.com/... it tells me Access denied.

This S3 bucket doesn't have any permission rules defined for Everyone.

However, accessing the same bucket via our CloudFront Domain Name a full ListBucketResult is being returned.

CloudFront is giving a full directory listing, which we want to prevent.

How can I disable that listing via CloudFront?

I tried invalidating all objects (*) in CloudFront, without effect.

like image 586
eoinoc Avatar asked Jan 17 '13 16:01

eoinoc


People also ask

How do I disable AWS CloudFront?

In the right pane of the CloudFront console, select the check box for the distribution that you want to delete. Choose Disable to disable the distribution, and choose Yes, Disable to confirm.

How do I prevent CloudFront from caching certain files?

Configuration on the origin On your custom origin web server application, add Cache-Control no-cache, no-store, or private directives to the objects that you don't want CloudFront to cache. Or, add Expires directives to the objects that you don't want CloudFront to cache.

Do S3 buckets need to be public for CloudFront?

By default, your Amazon S3 bucket and all the files in it are private—only the Amazon account that created the bucket has permission to read or write the files. If you want to allow anyone to access the files in your Amazon S3 bucket using CloudFront URLs, you must grant public read permissions to the objects.


2 Answers

Did you already get it? If not, you can try setting Default Root object for your cloudfront distribution.

like image 52
suresh Avatar answered Sep 18 '22 20:09

suresh


setting Default Root should work. Another option is to just put any index.html file at your root. You could take a blank text file and rename it "index.html", or put some generic HTML message in the file too. Either way, a call to root of your cloudfront distribution will just default to that file instead of listing your directories / files.

like image 20
Vette Avatar answered Sep 20 '22 20:09

Vette