Skip to content

Commit f9fc2da

Browse files
committed
feat: allow setting intrinsic functions for CW Events iamRole
1 parent 898752e commit f9fc2da

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

lib/deploy/events/cloudWatchEvent/compileCloudWatchEventEvents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = {
5151
Description = eventRule.description;
5252
Name = eventRule.name;
5353
EventBusName = JSON.stringify(eventRule.eventBusName);
54-
IamRole = eventRule.iamRole;
54+
IamRole = JSON.stringify(eventRule.iamRole);
5555
DeadLetterConfig = JSON.stringify(eventRule.deadLetterConfig);
5656

5757
if ([Input, InputPath, InputTransformer].filter(Boolean).length > 1) {
@@ -117,7 +117,7 @@ module.exports = {
117117
"Arn": { "Ref": "${stateMachineLogicalId}" },
118118
"Id": "${cloudWatchId}",
119119
${DeadLetterConfig ? `"DeadLetterConfig":{ "Arn" : ${DeadLetterConfig} },` : ''}
120-
${IamRole ? `"RoleArn":"${IamRole}"` : `"RoleArn": {
120+
${IamRole ? `"RoleArn": ${IamRole}` : `"RoleArn": {
121121
"Fn::GetAtt": [
122122
"${cloudWatchIamRoleLogicalId}",
123123
"Arn"

lib/deploy/events/cloudWatchEvent/compileCloudWatchEventEvents.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,66 @@ describe('awsCompileCloudWatchEventEvents', () => {
520520
.FirstEventsRuleCloudWatchEvent1.Properties.Targets[0].Input).to.equal('{"key":"value"}');
521521
});
522522

523+
itParam('should respect iamRole variable', ['cloudwatchEvent', 'eventBridge'], (source) => {
524+
serverlessStepFunctions.serverless.service.stepFunctions = {
525+
stateMachines: {
526+
first: {
527+
events: [
528+
{
529+
[source]: {
530+
event: {
531+
source: ['aws.ec2'],
532+
'detail-type': ['EC2 Instance State-change Notification'],
533+
detail: { state: ['pending'] },
534+
},
535+
enabled: false,
536+
input: '{"key":"value"}',
537+
name: 'test-event-name',
538+
iamRole: 'arn:aws:iam::012345678910:role/my-role',
539+
},
540+
},
541+
],
542+
},
543+
},
544+
};
545+
546+
serverlessStepFunctions.compileCloudWatchEventEvents();
547+
548+
expect(serverlessStepFunctions.serverless.service
549+
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleCloudWatchEvent1
550+
.Properties.Targets[0].RoleArn).to.equal('arn:aws:iam::012345678910:role/my-role');
551+
});
552+
553+
itParam('should respect iamRole intrinsic function', ['cloudwatchEvent', 'eventBridge'], (source) => {
554+
serverlessStepFunctions.serverless.service.stepFunctions = {
555+
stateMachines: {
556+
first: {
557+
events: [
558+
{
559+
[source]: {
560+
event: {
561+
source: ['aws.ec2'],
562+
'detail-type': ['EC2 Instance State-change Notification'],
563+
detail: { state: ['pending'] },
564+
},
565+
enabled: false,
566+
input: '{"key":"value"}',
567+
name: 'test-event-name',
568+
iamRole: '{"Fn::GetAtt": ["StepFunctionsRole", "Arn"]}',
569+
},
570+
},
571+
],
572+
},
573+
},
574+
};
575+
576+
serverlessStepFunctions.compileCloudWatchEventEvents();
577+
578+
expect(serverlessStepFunctions.serverless.service
579+
.provider.compiledCloudFormationTemplate.Resources.FirstEventsRuleCloudWatchEvent1
580+
.Properties.Targets[0].RoleArn).to.equal('{"Fn::GetAtt": ["StepFunctionsRole", "Arn"]}');
581+
});
582+
523583
it('should not create corresponding resources when events are not given', () => {
524584
serverlessStepFunctions.serverless.service.stepFunctions = {
525585
stateMachines: {

0 commit comments

Comments
 (0)