Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(events): rule cannot have more than 5 targets #30470

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-events/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/aws-events/test/rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down