Search code examples
amazon-web-servicesamazon-s3amazon-cloudfrontaws-cdk

Use AWS CDK to set up a CloudFrontWebDistribution to have GET /subdirectory server /subdirectory/index.html from an S3 bucket


I'm using the https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/static-site AWS CDK example to configure a Cloudfront + S3 bucket to serve a static site.

It does not seem like requests to GET /subdirectory responds with /subdirectory/index.html though. How would one use the CDK to configure Cloudfront + S3 to serve /subdirectory/index.html?


Solution

  • I ended up with a solution to create a Lambda@Edge function, which performed the Url Rewrite.

    https://briantakita.com/posts/static-https-websites-using-aws-cdk-cloudfront-and-s3

    The source code is contained in this gist.