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 2 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
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-events/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ export class Rule extends Resource implements IRule {
private renderTargets() {
if (this.targets.length === 0) {
return undefined;
} else if (this.targets.length > 5) {
flexelem marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Event rule cannot have more than 5 targets.');
}

return this.targets;
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