diff --git a/packages/aws-cdk-lib/aws-events/lib/rule.ts b/packages/aws-cdk-lib/aws-events/lib/rule.ts index b96347e20ba2b..bbac64b14e63a 100644 --- a/packages/aws-cdk-lib/aws-events/lib/rule.ts +++ b/packages/aws-cdk-lib/aws-events/lib/rule.ts @@ -314,6 +314,10 @@ export class Rule extends Resource implements IRule { errors.push('Either \'eventPattern\' or \'schedule\' must be defined'); } + if (this.targets.length > 5) { + errors.push('Event rule cannot have more than 5 targets.'); + } + return errors; } diff --git a/packages/aws-cdk-lib/aws-events/test/rule.test.ts b/packages/aws-cdk-lib/aws-events/test/rule.test.ts index 80f3c5cbe53d6..dbcf5ad9bd01c 100644 --- a/packages/aws-cdk-lib/aws-events/test/rule.test.ts +++ b/packages/aws-cdk-lib/aws-events/test/rule.test.ts @@ -72,6 +72,25 @@ describe('rule', () => { }); }); + test('rule cannot have more than 5 targets', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app); + const resource = new Construct(stack, 'Resource'); + const rule = new Rule(stack, 'MyRule', { + schedule: Schedule.rate(cdk.Duration.minutes(10)), + targets: [ + new SomeTarget('T1', resource), + new SomeTarget('T2', resource), + new SomeTarget('T3', resource), + new SomeTarget('T4', resource), + new SomeTarget('T5', resource), + new SomeTarget('T6', resource), + ], + }); + + expect(() => app.synth()).toThrow(/Event rule cannot have more than 5 targets./); + }); + test('get rate as token', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'MyScheduledStack');