1

I am loading a website with S3 and using Cloudfront for a CDN.

S3 website has public access and all pages load (verified by loading through s3 endpoint). However when I load the website somaloans.com, all pages that are not the home page (index file) receive the error below.

I was told to add the Default root object as index.html. That got the main page to work. but all other pages receive error below.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>GPMC172SDX7GSQ8Y</RequestId>
<HostId>Yad+tRp/3lOu1FG3wUU//0+YdfocLb8sKZZt62geYxUwv1f/qIcSlUyuNM/DlBKVdSN7jfrdvC4=</HostId>
</Error>
5
  • I went to your website and clicked on INVEST. It then linked to: https://somaloans.com/invest/ What object do you have in that path that should be displayed -- is it invest/index.html? If so, did you configure the index document when Enabling website hosting?
    – John Rotenstein
    Commented Feb 14, 2022 at 1:59
  • If you access your website by going to the S3 website (eg http://your-bucket-name.s3-website.us-west-2.amazonaws.com/invest/index.html) is the page displayed?
    – John Rotenstein
    Commented Feb 14, 2022 at 2:01
  • @JohnRotenstein, I just went to somaloans.com/invest/index.html and it seems to be working man.
    – Allan Chua
    Commented Feb 14, 2022 at 2:12
  • @JohnRotenstein my goal is for folks to be able to go to somaloans.com/invest without having to input the index.html. The S3 bucket link displays the page. My guess is that it tagged the 'index.html' at the end without it showing? I may have found an easy solution here: fernandomc.com/posts/… I'll see if it works in a few hours...
    – Tony Correia
    Commented Feb 14, 2022 at 4:27
  • What is the underlying object that you would like displayed when somebody goes to /invest? Is it invest/index.html that should be displayed?
    – John Rotenstein
    Commented Feb 14, 2022 at 5:23

1 Answer 1

1

If you've enabled static site hosting and assigned origin access identity with enough permissions to view everything in the bucket. In Terraform, it would look something like this:

resource "aws_cloudfront_origin_access_identity" "website_oai" {
  comment = join("", ["Origin access identity of ", var.project_name, " Cloudfront."])
}

data "aws_iam_policy_document" "website_s3_iam_policy" {
  statement {
    actions   = ["s3:GetObject"]
    resources = ["${aws_s3_bucket.website_bucket.arn}/*"]

    principals {
      type        = "AWS"
      identifiers = [aws_cloudfront_origin_access_identity.website_oai.iam_arn]
    }
  }
}

If providing permissions to all the objects inside the bucket does not work, It seems that you will have to configure a redirection rule on S3 itself. Here is a link that shares at least 3 steps to do this.

To configure redirection rules for a static website and add redirection rules for a bucket that already has static website hosting enabled, follow these steps.

  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the Buckets list, choose the name of a bucket that you have configured as a static website.

  3. Choose Properties.

  4. Under Static website hosting, choose Edit.

  5. In Redirection rules box, enter your redirection rules in JSON.

  6. In the S3 console you describe the rules using JSON. For JSON examples, see Redirection rules examples. Amazon S3 has a limitation of 50 routing rules per website configuration.

Recommending the layering of your automation by separating provisioning and application automation by using Terraform or/and Cloud Formation for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.