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

fix scheduler role #12030

Merged
merged 4 commits into from Jun 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/plugins/aws/package/compile/events/schedule.js
Expand Up @@ -136,9 +136,11 @@ class AwsCompileScheduledEvents {
Name = event.schedule.name;
timezone = event.schedule.timezone;
Description = event.schedule.description;
roleArn = {
'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'],
};

const functionLogicalId = this.provider.naming.getLambdaLogicalId(functionName);
const functionResource = resources[functionLogicalId];

roleArn = functionResource.Properties.Role;

method = event.schedule.method || METHOD_EVENT_BUS;

Expand Down
Expand Up @@ -10,7 +10,7 @@ const METHOD_EVENT_BUS = 'eventBus';

chaiUse(chaiAsPromised);

async function run(events) {
async function run(events, options = {}) {
const params = {
fixture: 'function',
command: 'package',
Expand All @@ -19,6 +19,7 @@ async function run(events) {
test: {
handler: 'index.handler',
events,
role: options.functionRole,
},
},
},
Expand Down Expand Up @@ -414,4 +415,24 @@ describe('test/unit/lib/plugins/aws/package/compile/events/schedule.test.js', ()
it('should not create schedule resources when no scheduled event is given', async () => {
expect((await run([])).scheduleCfResources).to.be.empty;
});

it('should pass the custom roleArn to method:schedule resources', async () => {
const events = [
{
schedule: {
rate: 'rate(15 minutes)',
method: METHOD_SCHEDULER,
name: 'scheduler-scheduled-event',
description: 'Scheduler Scheduled Event',
input: '{"key":"array"}',
},
},
];

const { scheduleCfResources } = await run(events, { functionRole: 'customRole' });

expect(scheduleCfResources[0].Properties.Target.RoleArn).to.deep.equal({
'Fn::GetAtt': ['customRole', 'Arn'],
});
});
});