Skip to content

Commit a05591d

Browse files
authored
chore(events): rule cannot have more than 5 targets (#30470)
### Issue # (if applicable) Closes #<issue number here>. ### Reason for this change This is a minor refactor for preventing an Event Rule to have at most 5 associated targets defined during a synth. This is the main limit set by EventBridge https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-quota.html#eb-limits ### Description of changes This is a very simple change in `aws-events` module to check if the `targets` array length of an `Event` is greater than 5. If it is then it throws an Error during build time. ### Description of how you validated changes Added a unit test by in `rule.test.ts` by verifying an Error is being thrown when a Rule has more than 5 associated targets. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 312235a commit a05591d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/aws-cdk-lib/aws-events/lib/rule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ export class Rule extends Resource implements IRule {
314314
errors.push('Either \'eventPattern\' or \'schedule\' must be defined');
315315
}
316316

317+
if (this.targets.length > 5) {
318+
errors.push('Event rule cannot have more than 5 targets.');
319+
}
320+
317321
return errors;
318322
}
319323

packages/aws-cdk-lib/aws-events/test/rule.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ describe('rule', () => {
7272
});
7373
});
7474

75+
test('rule cannot have more than 5 targets', () => {
76+
const app = new cdk.App();
77+
const stack = new cdk.Stack(app);
78+
const resource = new Construct(stack, 'Resource');
79+
const rule = new Rule(stack, 'MyRule', {
80+
schedule: Schedule.rate(cdk.Duration.minutes(10)),
81+
targets: [
82+
new SomeTarget('T1', resource),
83+
new SomeTarget('T2', resource),
84+
new SomeTarget('T3', resource),
85+
new SomeTarget('T4', resource),
86+
new SomeTarget('T5', resource),
87+
new SomeTarget('T6', resource),
88+
],
89+
});
90+
91+
expect(() => app.synth()).toThrow(/Event rule cannot have more than 5 targets./);
92+
});
93+
7594
test('get rate as token', () => {
7695
const app = new cdk.App();
7796
const stack = new cdk.Stack(app, 'MyScheduledStack');

0 commit comments

Comments
 (0)