aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.72k stars 3.94k forks source link

(events): Unable to use content based filtering patterns in detailType #30220

Open scub opened 6 months ago

scub commented 6 months ago

Describe the bug

When using the L2 construct for EventBridge Rules a type failure occurs when attempting to create an event bridge rule that uses content based filtering patterns. Requiring the use of a trapdoor in order to achieve the desired results.

Expected Behavior

Content based filtering patterns are supported in an events detailType

Current Behavior

Type '{ prefix: string; }' is not assignable to type 'string'

Reproduction Steps

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Rule, CfnRule } from 'aws-cdk-lib/aws-events';

const app = new cdk.App();

const stack = new cdk.Stack(app, 'RuleTestStack');

const rule = new Rule(stack, 'Rule', {
  eventPattern: {
    detailType: [{"prefix": "shared_"}]
  }
});

Possible Solution

See https://github.com/aws/aws-cdk/pull/30222

Using a trapdoor does provide a work around

(rule.node.defaultChild as CfnRule).addOverride('Properties.EventPattern.detail-type', [{"prefix": "shared_"}])

Additional Information/Context

No response

CDK CLI Version

2.141.0

Framework Version

No response

Node.js Version

18.18.0

OS

OSX

Language

TypeScript

Language Version

Typescript 5.4.0

Other information

No response

pahud commented 6 months ago

Thank you for your PR.

victorskl commented 5 months ago

We hit to similar issue but with source field for us. We went with @ts-ignore for now. It is not an issue at EventBirdge rule side and, accepting it.

// @ts-ignore
source: [{ "anything-but": "orcabus.workflowmanager" }],
snowe2010 commented 1 month ago

Same issue here, except we use the java cdk (through Kotlin) and this is thus not resolvable at all due to the typing. On the typescript side we were able to resolve it with // @ts-ignore as well, but we're SOL with the Java CDK.