Skip to content

Commit 1b00b1c

Browse files
authored
Merge pull request #143 from jerolan/main
add optional roleArn support for scheduler schedules
2 parents f2079f6 + fb28ae9 commit 1b00b1c

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

docs/events/schedule.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ However, `AWS::Scheduler::Schedule` has much higher limits (1,000,000 events), a
8888
`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.
8989
The default method is `eventBus`, which configures an `AWS::Event::Rule`.
9090

91+
By default, `scheduler` uses the function execution role as target role.
92+
You can provide `roleArn` to use a dedicated role for EventBridge Scheduler.
93+
9194
```yaml
9295
functions:
9396
foo:
9497
handler: foo.handler
9598
events:
9699
- schedule:
97100
method: scheduler
101+
roleArn: arn:aws:iam::123456789012:role/scheduler-execution-role
98102
rate:
99103
- cron(0 0/4 ? * MON-FRI *)
100104
timezone: America/New_York

lib/plugins/aws/package/compile/events/schedule.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AwsCompileScheduledEvents {
8282
type: 'string',
8383
enum: [METHOD_EVENT_BUS, METHOD_SCHEDULER],
8484
},
85+
roleArn: {
86+
anyOf: [{ type: 'string' }, { $ref: '#/definitions/awsCfFunction' }],
87+
},
8588
timezone: {
8689
type: 'string',
8790
pattern: '[\\w\\-\\/]+',
@@ -140,7 +143,7 @@ class AwsCompileScheduledEvents {
140143
const functionLogicalId = this.provider.naming.getLambdaLogicalId(functionName);
141144
const functionResource = resources[functionLogicalId];
142145

143-
roleArn = functionResource.Properties.Role;
146+
roleArn = event.schedule.roleArn || functionResource.Properties.Role;
144147

145148
method = event.schedule.method || METHOD_EVENT_BUS;
146149

test/unit/lib/plugins/aws/package/compile/events/schedule.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,25 @@ describe('test/unit/lib/plugins/aws/package/compile/events/schedule.test.js', ()
435435
'Fn::GetAtt': ['customRole', 'Arn'],
436436
});
437437
});
438+
439+
it('should pass explicit schedule roleArn to method:schedule resources', async () => {
440+
const events = [
441+
{
442+
schedule: {
443+
rate: 'rate(15 minutes)',
444+
method: METHOD_SCHEDULER,
445+
roleArn: 'arn:aws:iam::123456789012:role/scheduler-execution-role',
446+
name: 'scheduler-scheduled-event',
447+
description: 'Scheduler Scheduled Event',
448+
input: '{"key":"array"}',
449+
},
450+
},
451+
];
452+
453+
const { scheduleCfResources } = await run(events, { functionRole: 'customRole' });
454+
455+
expect(scheduleCfResources[0].Properties.Target.RoleArn).to.equal(
456+
'arn:aws:iam::123456789012:role/scheduler-execution-role'
457+
);
458+
});
438459
});

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export interface AWS {
205205
};
206206
};
207207
method?: "eventBus" | "scheduler";
208+
roleArn?: AwsCfFunction | string;
208209
timezone?: string;
209210
};
210211
}

0 commit comments

Comments
 (0)