aws-cdk: s3: websiteRoutingRule doesn't allow empty keyPrefixEquals
Describe the bug
When setting up an S3 bucket with
{
condition: { keyPrefixEquals: "" },
protocol: RedirectProtocol.HTTPS,
hostName: "example.com",
replaceKey: ReplaceKey.with("/"),
},
it causes
Error: The condition property cannot be an empty object
Expected Behavior
It should work.
Current Behavior
Error: The condition property cannot be an empty object
Reproduction Steps
Set up a bucket with
{
condition: { keyPrefixEquals: "" },
protocol: RedirectProtocol.HTTPS,
hostName: "example.com",
replaceKey: ReplaceKey.with("/"),
},
Possible Solution
In this line: https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-s3/lib/bucket.ts#L2321
it should be
if (rule.condition && rule.condition.httpErrorCodeReturnedEquals != null && rule.condition.keyPrefixEquals != null) {
instead of
if (rule.condition && !rule.condition.httpErrorCodeReturnedEquals && !rule.condition.keyPrefixEquals) {
Additional Information/Context
No response
CDK CLI Version
2.72.1
Framework Version
No response
Node.js Version
16.14.12
OS
Mac
Language
Typescript
Language Version
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (15 by maintainers)
Commits related to this issue
- Allow empty string as keyPrefixEquals See #26242 — committed to dbartholomae/aws-cdk by dbartholomae a year ago
- Allow empty string as keyPrefixEquals See #26242 — committed to dbartholomae/aws-cdk by dbartholomae a year ago
- fix(s3): allow empty string as keyPrefixEquals (#26243) Closes #26242 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* — committed to aws/aws-cdk by dbartholomae a year ago
- fix(s3): allow empty string as keyPrefixEquals (#26243) Closes #26242 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* — committed to aws/aws-cdk by dbartholomae a year ago
- fix(s3): allow empty string as keyPrefixEquals (#26243) Closes #26242 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* — committed to bmoffatt/aws-cdk by dbartholomae a year ago
The goal in this case is that every single request is redirected to the same domain (not only the root).
@peterwoodworth good question! I know that I can set this manually. I’ll try to set it via CloudFormation to confirm tomorrow.