-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
EventBridge rules allow for content filtering. One type is {"anything-but": ...}.
I want to create an EventBridge Rule with CDK that specifies an anything-but filter for the rule's resources block. The EventPattern of the CDK Rule construct requires that resources be a string[], assuming ARN(s) are the only kinds of values that might be used.
Can the CDK EventPattern construct be changed such that resources (and any others that can accept content filters via CFN) are any-typed, so that they can be used as fluently as raw CFN allows?
Expected Behavior
CDK Rule and EventPattern constructs should allow the specification of content filters, as documented here.
Current Behavior
If I use:
new events.Rule(this, "Trigger", {
description: "...",
eventPattern: {
source: ["aws.dataexchange"],
detailType: ["Revision Published To Data Set"]
// All subscribed ADX data sets EXCEPT this one
resources: [{"anything-but": "aae4c2cd145a48454f9369d4a4db5c66"}
},
targets: [new targets.SqsQueue(...)]
});
Then an error is thrown, that:
error TS2322: Type '{ "anything-but": string; }' is not assignable to type 'string'.
Understandable. The CDK EventPattern construct is too strictly typed, and should probably be any[] instead.
Reproduction Steps
Workaround:
I tried to use the escape hatch, and set the same in the CfnRule construct:
(rule.node.defaultChild as events.CfnRule).eventPattern["resources"] = [
{"anything-but": "aae4c2cd145a48454f9369d4a4db5c66"}
]
But it seems to have no effect on the generated CFN.
Trying it this way throws errors about the EventPattern being a LazyAny and fails to compile:
const cfnRule = rule.node.defaultChild as events.CfnRule
cfnRule.eventPattern = {
...cfnRule.eventPattern,
resources: [{"anything-but": "aae4c2cd145a48454f9369d4a4db5c66"}]
}
This solution finally worked:
(rule.node.defaultChild as events.CfnRule).addPropertyOverride(
"EventPattern.resources",
[{"anything-but": "aae4c2cd145a48454f9369d4a4db5c66"}]
);
And generated the intended CFN that gets the desired effect when deployed.
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.x
Framework Version
No response
Node.js Version
14.x
OS
macOS
Language
Typescript
Language Version
No response
Other information
No response