I am looking into serving my static site with Amazon S3. I have created a bucket and uploaded my files; under the “Website” tab in the AWS Management Console I have checked “Enabled” and entered index.html
in the “Index Document” field. I have the following bucket policy:
{ "Version": "2008-10-17", "Id": "924a2348-de0e-43aa-bb06-83adbcd1db22", "Statement": [ { "Sid": "PublicReadForGetBucketObjects", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-bucket/*" } ] }
where I have my bucket’s name instead of my-bucket
. Under the “Permissions” tab I have also granted “Everyone” the list ability.
If I try to access my-bucket.s3.amazonaws.com/index.html
my page (and its images, CSS, etc.) shows up as expected. However, just going to my-bucket.s3.amazonaws.com
or my-bucket.s3.amazonaws.com/
gives a directory-listing XML file instead of showing the page. If I try to go to my-bucket.s3.amazonaws.com/subdirectory
I get an error (in XML) saying “The specified key does not exist.” Most bizarrely, if I try to go to my-bucket.s3.amazonaws.com/subdirectory/
(with a trailing slash), no page loads but my browser downloads an empty file named download
. (Once again, going to my-bucket.s3.amazonaws.com/subdirectory/index.html
shows the page as expected.)
Am I doing something wrong here? How do I get S3 to show the index.html
file when a directory name is requested?
However, if you exclude the trailing slash from the preceding URL, Amazon S3 first looks for an object photos in the bucket. If the photos object is not found, it searches for an index document, photos/index. html . If that document is found, Amazon S3 returns a 302 Found message and points to the photos/ key.
If you're trying to host a static website using Amazon S3, but you're getting an Access Denied error, check the following requirements: Objects in the bucket must be publicly accessible. S3 bucket policy must allow access to the s3:GetObject action. The AWS account that owns the bucket must also own the object.
Looks like you need to configure a root (index) document:
http://docs.amazonwebservices.com/AmazonS3/latest/dev/IndexDocumentSupport.html
http://aws.typepad.com/aws/2011/02/host-your-static-website-on-amazon-s3.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With