CloudFront defaultRootObject should not quietly default to index.html
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
* **I'm submitting a ...**
- [x] :beetle: bug report
* **What is the current behavior?**
This really caught me by surprise. If you leave out the defaultRootObject property from CloudFront Distribution properties, AWS CDK quietly defaults it to 'index.html', which causes all kinds of weird problems.
For instance, when using a S3 bucket origin to redirect "www.example.org" to "example.org", this default causes the redirect Location header actually point to "example.org/index.html" which is not useful.
* **What is the expected behavior (or behavior of feature suggested)?**
I would suggest to remove the logic from https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-cloudfront/lib/web_distribution.ts#L559 which quietly defaults defaultRootObject to 'index.html'. This would allow the CDK Construct to work in the same way as CloudFormation, and by default just pass requests through CloudFront as they are.
This quiet default is also not documented in the CloudFrontWebDistribution Constructor Props section. You have to scroll down and read the entry about defaultRootObject to notice it at all. It's very easy to miss. If the default stays as it is, I would suggest to at least mention it clearly in the Constructor Props section.
* **What is the motivation / use case for changing the behavior or adding this feature?**
IMHO it's really best to let the Origin handle default documents according to its own logic and just let CloudFront pass requests through as they are. For instance, S3 website endpoints will handle default documents correctly for any subfolders, while the CloudFront defaultRootObject setting only affects the root folder and is not very useful in general.
* **Please tell us about your environment:**
- CDK CLI Version: 1.2.0
- Module Version: 1.2.0
- OS: Ubuntu
- Language: TypeScript
Contributor guide
Research direction
Start in packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts at the defaultRootObject logic around line 559, then read the CloudFrontWebDistribution Constructor Props documentation. Verify how the construct currently handles an omitted value versus CloudFormation, and define done as removing the surprising default or clearly documenting it if the behavior is retained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100