(custom-resources): not sorting filter rules on put bucket notification configuration causes error #31413
Labels
@aws-cdk/custom-resources
Related to AWS CDK Custom Resources
bug
This issue is a bug.
duplicate
This issue is a duplicate.
p2
Describe the bug
When calling
addEventNotification
on an S3 BucketWe get a failure for the S3 API indicating overlapping rules:
An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Configuration is ambiguously defined. Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type
After debugging my specific scenario - it turns out the order of the FilterRules passed as input to the custom resource vs what is returned by the S3.Client.get_bucket_notification_configuration don't always match.
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
I expect to generate the same ID regardless of the ordering of the
FilterRules
array returned in the S3 API response and successfully put the notification configuration when these things are out of order.Current Behavior
An error occurred (InvalidArgument) when calling the PutBucketNotificationConfiguration operation: Configuration is ambiguously defined. Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type
Reproduction Steps
Since I'm short on time I am not going to reproduce an entire CDK app that exhibits this problem since it also involves some existing state. A quick way to test this in isolation is:
Possible Solution
Introduce a function
recursive_sort()
that will sort all dicts/objects in the response. In the event the response ordering does change this will ensure the hash generated will remain the same by recursively sorting all levels.Additional Information/Context
I'm not sure why/how the order doesn't match what's returned in the API. We haven't touched this code in quiet some time so something at some layer (s3 api, boto3, etc) changed that broke this.
CDK CLI Version
2.115.0 (build 58027ee)
Framework Version
No response
Node.js Version
v18.19.0
OS
macos
Language
TypeScript, Python
Language Version
TypesScript (5.5.4) | Python (3.12.3)
Other information
No response
The text was updated successfully, but these errors were encountered: