From 07356e2719c493163c68dfb103dcce3e63b31900 Mon Sep 17 00:00:00 2001 From: Fabien Foulgoc Date: Tue, 26 May 2026 16:36:07 +0200 Subject: [PATCH 1/2] feat(schedule): add support for groupName --- docs/events/schedule.md | 8 +++- .../aws/package/compile/events/schedule.js | 20 ++++++++ .../package/compile/events/schedule.test.js | 47 +++++++++++++++++++ types/index.d.ts | 1 + 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/docs/events/schedule.md b/docs/events/schedule.md index cd4a768dd..58746df31 100644 --- a/docs/events/schedule.md +++ b/docs/events/schedule.md @@ -88,8 +88,11 @@ However, `AWS::Scheduler::Schedule` has much higher limits (1,000,000 events), a `method` can be set in order to migrate to this trigger type seamlessly. It also allows you to specify a timezone to run your event based on local time. The default method is `eventBus`, which configures an `AWS::Event::Rule`. -By default, `scheduler` uses the function execution role as target role. -You can provide `roleArn` to use a dedicated role for EventBridge Scheduler. +By default, `scheduler` uses the function execution role as the target role and the `default` schedule group. + +You can provide: +- roleArn to use a dedicated role for EventBridge Scheduler. +- groupName to use another EventBridge Scheduler schedule group. ```yaml functions: @@ -99,6 +102,7 @@ functions: - schedule: method: scheduler roleArn: arn:aws:iam::123456789012:role/scheduler-execution-role + groupName: custom-scheduler-group rate: - cron(0 0/4 ? * MON-FRI *) timezone: America/New_York diff --git a/lib/plugins/aws/package/compile/events/schedule.js b/lib/plugins/aws/package/compile/events/schedule.js index 0d12b46af..63ac9e078 100644 --- a/lib/plugins/aws/package/compile/events/schedule.js +++ b/lib/plugins/aws/package/compile/events/schedule.js @@ -85,6 +85,17 @@ class AwsCompileScheduledEvents { roleArn: { anyOf: [{ type: 'string' }, { $ref: '#/definitions/awsCfFunction' }], }, + groupName: { + anyOf: [ + { + type: 'string', + minLength: 1, + maxLength: 64, + pattern: '^[0-9a-zA-Z-_.]+$', + }, + { $ref: '#/definitions/awsCfFunction' }, + ], + }, timezone: { type: 'string', pattern: '[\\w\\-\\/]+', @@ -124,6 +135,7 @@ class AwsCompileScheduledEvents { let Description; let method; let roleArn; + let groupName; let timezone; if (typeof event.schedule === 'object') { @@ -137,6 +149,7 @@ class AwsCompileScheduledEvents { InputPath = event.schedule.inputPath; InputTransformer = event.schedule.inputTransformer; Name = event.schedule.name; + groupName = event.schedule.groupName; timezone = event.schedule.timezone; Description = event.schedule.description; @@ -186,6 +199,12 @@ class AwsCompileScheduledEvents { 'SCHEDULE_PARAMETER_NOT_SUPPORTED' ); } + if (groupName && method !== METHOD_SCHEDULER) { + throw new ServerlessError( + 'Cannot setup "schedule" event: "groupName" is only supported with "scheduler" mode', + 'SCHEDULE_PARAMETER_NOT_SUPPORTED' + ); + } } else { ScheduleExpressions = [event.schedule]; State = 'ENABLED'; @@ -227,6 +246,7 @@ class AwsCompileScheduledEvents { Mode: 'OFF', }, Name, + GroupName: groupName, Description, ScheduleExpressionTimezone: timezone, }, diff --git a/test/unit/lib/plugins/aws/package/compile/events/schedule.test.js b/test/unit/lib/plugins/aws/package/compile/events/schedule.test.js index 5f13df915..18bd485fb 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/schedule.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/schedule.test.js @@ -380,6 +380,37 @@ describe('test/unit/lib/plugins/aws/package/compile/events/schedule.test.js', () .and.have.property('code', 'SCHEDULE_PARAMETER_NOT_SUPPORTED'); }); + it('should throw when passing "groupName" to method:eventBus resources', async () => { + const events = [ + { + schedule: { + rate: 'rate(15 minutes)', + method: METHOD_EVENT_BUS, + groupName: 'custom-scheduler-group', + }, + }, + ]; + + await expect(run(events)) + .to.be.eventually.rejectedWith(ServerlessError) + .and.have.property('code', 'SCHEDULE_PARAMETER_NOT_SUPPORTED'); + }); + + it('should throw when passing "groupName" without method:scheduler specified', async () => { + const events = [ + { + schedule: { + rate: 'rate(15 minutes)', + groupName: 'custom-scheduler-group', + }, + }, + ]; + + await expect(run(events)) + .to.be.eventually.rejectedWith(ServerlessError) + .and.have.property('code', 'SCHEDULE_PARAMETER_NOT_SUPPORTED'); + }); + it('should have not scheduler policies when there are no scheduler schedules', async () => { const events = [ { @@ -453,4 +484,20 @@ describe('test/unit/lib/plugins/aws/package/compile/events/schedule.test.js', () 'arn:aws:iam::123456789012:role/scheduler-execution-role' ); }); + + it('should pass explicit schedule groupName to method:scheduler resources', async () => { + const events = [ + { + schedule: { + rate: 'rate(15 minutes)', + method: METHOD_SCHEDULER, + groupName: 'custom-scheduler-group', + }, + }, + ]; + + const { scheduleCfResources } = await run(events); + + expect(scheduleCfResources[0].Properties.GroupName).to.equal('custom-scheduler-group'); + }); }); diff --git a/types/index.d.ts b/types/index.d.ts index 2821466a9..7d3d8acb2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -195,6 +195,7 @@ export interface AWS { }; method?: 'eventBus' | 'scheduler'; roleArn?: AwsCfFunction | string; + groupName?: AwsCfFunction | string; timezone?: string; }; } From 1cd47a0ea5e4bc8f2701d780aaf9f6eb1ab3c54c Mon Sep 17 00:00:00 2001 From: Fabien Foulgoc Date: Tue, 26 May 2026 16:41:51 +0200 Subject: [PATCH 2/2] lint-fix --- docs/events/schedule.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/events/schedule.md b/docs/events/schedule.md index 58746df31..5cca5f0fe 100644 --- a/docs/events/schedule.md +++ b/docs/events/schedule.md @@ -91,6 +91,7 @@ The default method is `eventBus`, which configures an `AWS::Event::Rule`. By default, `scheduler` uses the function execution role as the target role and the `default` schedule group. You can provide: + - roleArn to use a dedicated role for EventBridge Scheduler. - groupName to use another EventBridge Scheduler schedule group.