Skip to content

Commit 0dbfecf

Browse files
committed
fix: scheduled events + tests
1 parent 7070ae5 commit 0dbfecf

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

lib/deploy/events/schedule/compileScheduledEvents.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const BbPromise = require('bluebird');
55

66
module.exports = {
77
compileScheduledEvents() {
8+
const service = this.serverless.service;
9+
const permissionsBoundary = service.provider.rolePermissionsBoundary;
810
_.forEach(this.getAllStateMachines(), (stateMachineName) => {
911
const stateMachineObj = this.getStateMachine(stateMachineName);
1012
let scheduleNumberInFunction = 0;
@@ -131,7 +133,7 @@ module.exports = {
131133
}
132134
`;
133135

134-
const iamRoleTemplate = `
136+
let iamRoleTemplate = `
135137
{
136138
"Type": "AWS::IAM::Role",
137139
"Properties": {
@@ -169,6 +171,11 @@ module.exports = {
169171
}
170172
}
171173
`;
174+
if (permissionsBoundary) {
175+
const jsonIamRole = JSON.parse(iamRoleTemplate);
176+
jsonIamRole.Properties.PermissionsBoundary = permissionsBoundary;
177+
iamRoleTemplate = JSON.stringify(jsonIamRole);
178+
}
172179

173180
const newScheduleObject = {
174181
[scheduleLogicalId]: JSON.parse(scheduleTemplate),

lib/deploy/events/schedule/compileScheduledEvents.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,28 @@ describe('#httpValidate()', () => {
423423
expect(() => serverlessStepFunctions.compileScheduledEvents()).to.throw(Error);
424424
});
425425
});
426+
it('should handle permissionsBoundary', () => {
427+
serverlessStepFunctions.serverless.service.stepFunctions = {
428+
stateMachines: {
429+
first: {
430+
events: [
431+
{
432+
schedule: {
433+
rate: 'rate(10 minutes)',
434+
enabled: false,
435+
inputPath: '$.stageVariables',
436+
},
437+
},
438+
],
439+
},
440+
},
441+
};
442+
serverless.service.provider.rolePermissionsBoundary = 'arn:aws:iam::myAccount:policy/permission_boundary';
443+
serverlessStepFunctions.compileScheduledEvents();
444+
445+
expect(serverlessStepFunctions.serverless.service
446+
.provider.compiledCloudFormationTemplate.Resources
447+
.FirstScheduleToStepFunctionsRole
448+
.Properties.PermissionsBoundary).to.equal('arn:aws:iam::myAccount:policy/permission_boundary');
449+
});
426450
});

lib/deploy/stepFunctions/compileIamRole.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,4 +2647,30 @@ describe('#compileIamRole', () => {
26472647
},
26482648
]);
26492649
});
2650+
it('should handle permissionsBoundary', () => {
2651+
serverless.service.stepFunctions = {
2652+
stateMachines: {
2653+
myStateMachine1: {
2654+
id: 'StateMachine1',
2655+
definition: {
2656+
StartAt: 'A',
2657+
States: {
2658+
A: {
2659+
Type: 'Task',
2660+
Resource:
2661+
'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello',
2662+
End: true,
2663+
},
2664+
},
2665+
},
2666+
},
2667+
},
2668+
};
2669+
serverless.service.provider.rolePermissionsBoundary = 'arn:aws:iam::myAccount:policy/permission_boundary';
2670+
serverlessStepFunctions.compileIamRole();
2671+
const boundary = serverlessStepFunctions.serverless.service.provider
2672+
.compiledCloudFormationTemplate.Resources.StateMachine1Role.Properties
2673+
.PermissionsBoundary;
2674+
expect(boundary).to.equal('arn:aws:iam::myAccount:policy/permission_boundary');
2675+
});
26502676
});

lib/deploy/stepFunctions/compileNotifications.test.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -522,31 +522,4 @@ describe('#compileNotifications', () => {
522522
expect(logMessage.startsWith('State machine [Beta1] : notifications are not supported on Express Workflows.'))
523523
.to.equal(true);
524524
});
525-
526-
it('should handle permissionsBoundary', () => {
527-
serverless.service.stepFunctions = {
528-
stateMachines: {
529-
myStateMachine1: {
530-
id: 'StateMachine1',
531-
definition: {
532-
StartAt: 'A',
533-
States: {
534-
A: {
535-
Type: 'Task',
536-
Resource:
537-
'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello',
538-
End: true,
539-
},
540-
},
541-
},
542-
},
543-
},
544-
};
545-
serverless.service.provider.rolePermissionsBoundary = 'arn:aws:iam::myAccount:policy/permission_boundary';
546-
serverlessStepFunctions.compileIamRole();
547-
const boundary = serverlessStepFunctions.serverless.service.provider
548-
.compiledCloudFormationTemplate.Resources.StateMachine1Role.Properties
549-
.PermissionsBoundary;
550-
expect(boundary).to.equal('arn:aws:iam::myAccount:policy/permission_boundary');
551-
});
552525
});

0 commit comments

Comments
 (0)