title: How do you set a default root object for subdirectories for a statically hosted website on Cloudfront?
body: <p>How do you set a default root object for subdirectories on a statically hosted website on Cloudfront?  Specifically, I'd like <code>www.example.com/subdir/index.html</code> to be served whenever the user asks for <code>www.example.com/subdir</code>.  Note, this is for delivering a static website held in an S3 bucket.  In addition, I would like to use an origin access identity to restrict access to the S3 bucket to only Cloudfront.</p>
  
  <p>Now, I am aware that Cloudfront works differently than S3 and amazon states <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html" rel="noreferrer">specifically</a>:</p>
  
  <blockquote>
    <p>The behavior of CloudFront default root objects is different from the
    behavior of Amazon S3 index documents. When you configure an Amazon S3
    bucket as a website and specify the index document, Amazon S3 returns
    the index document even if a user requests a subdirectory in the
    bucket. (A copy of the index document must appear in every
    subdirectory.) For more information about configuring Amazon S3
    buckets as websites and about index documents, see the Hosting
    Websites on Amazon S3 chapter in the Amazon Simple Storage Service
    Developer Guide.</p>
  </blockquote>
  
  <p>As such, even though Cloudfront allows us to specify a default root object, this only works for <code>www.example.com</code> and not for <code>www.example.com/subdir</code>.  In order to get around this difficulty, we can change the origin domain name to point to the website endpoint given by S3.  This works great and allows the root objects to be specified uniformly.  Unfortunately, this doesn't appear to be compatable with <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html" rel="noreferrer">origin access identities</a>.  Specifically, the above links states:</p>
  
  <blockquote>
    <p>Change to edit mode:</p>
    
    <p>Web distributions – Click the Origins tab, click the origin that you want to edit, and click Edit. You can only create an origin access
    identity for origins for which Origin Type is S3 Origin.</p>
  </blockquote>
  
  <p>Basically, in order to set the correct default root object, we use the S3 website endpoint and not the website bucket itself.  This is not compatible with using origin access identity.  As such, my questions boils down to either</p>
  
  <ol>
  <li><p>Is it possible to specify a default root object for all subdirectories for a statically hosted website on Cloudfront?</p></li>
  <li><p>Is it possible to setup an origin access identity for content served from Cloudfront where the origin is an S3 website endpoint and not an S3 bucket?</p></li>
  </ol>