Closed rcalme closed 2 years ago
A simpler workaround could be to override the type as any[]
resources: [{"anything-but": "aae4c2cd145a48454f9369d4a4db5c66"}] as any[]
I think this issue is broader - it doesn't appear possible to define expressions on any of the built in fields (source|account|region|resources|detail-type|time|version
).
So far I'm also not able to workaround in the Java SDK using unchecked casts. Here's a workaround using an escape hatch:
// Workaround https://github.com/aws/aws-cdk/issues/20486
((CfnRule) rule.getNode().getDefaultChild()).setEventPattern(Map.of("source", List.of(Map.of("exists", true))));
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
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'sresources
block. The EventPattern of the CDK Rule construct requires thatresources
be astring[]
, assuming ARN(s) are the only kinds of values that might be used.Can the CDK
EventPattern
construct be changed such thatresources
(and any others that can accept content filters via CFN) areany
-typed, so that they can be used as fluently as raw CFN allows?Expected Behavior
CDK
Rule
andEventPattern
constructs should allow the specification of content filters, as documented here.Current Behavior
If I use:
Then an error is thrown, that:
Understandable. The CDK
EventPattern
construct is too strictly typed, and should probably beany[]
instead.Reproduction Steps
Workaround:
I tried to use the escape hatch, and set the same in the
CfnRule
construct:But it seems to have no effect on the generated CFN.
Trying it this way throws errors about the
EventPattern
being aLazyAny
and fails to compile:This solution finally worked:
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