@@ -512,22 +512,22 @@ describe('#compileIamRole', () => {
512
512
] ,
513
513
} ;
514
514
515
- const genStateMachine = ( id , tableName ) => ( {
515
+ const genStateMachine = ( id , tableName , resources ) => ( {
516
516
id,
517
517
definition : {
518
518
StartAt : 'A' ,
519
519
States : {
520
520
A : {
521
521
Type : 'Task' ,
522
- Resource : 'arn:aws:states:::dynamodb:updateItem' ,
522
+ Resource : resources [ 0 ] ,
523
523
Parameters : {
524
524
TableName : tableName ,
525
525
} ,
526
526
Next : 'B' ,
527
527
} ,
528
528
B : {
529
529
Type : 'Task' ,
530
- Resource : 'arn:aws:states:::dynamodb:putItem' ,
530
+ Resource : resources [ 1 ] ,
531
531
Parameters : {
532
532
TableName : tableName ,
533
533
} ,
@@ -555,8 +555,10 @@ describe('#compileIamRole', () => {
555
555
556
556
serverless . service . stepFunctions = {
557
557
stateMachines : {
558
- myStateMachine1 : genStateMachine ( 'StateMachine1' , helloTable ) ,
559
- myStateMachine2 : genStateMachine ( 'StateMachine2' , worldTable ) ,
558
+ myStateMachine1 : genStateMachine ( 'StateMachine1' , helloTable , [ 'arn:aws:states:::dynamodb:updateItem' , 'arn:aws:states:::dynamodb:putItem' ] ) ,
559
+ myStateMachine2 : genStateMachine ( 'StateMachine2' , worldTable , [ 'arn:aws:states:::dynamodb:updateItem' , 'arn:aws:states:::dynamodb:putItem' ] ) ,
560
+ myStateMachine3 : genStateMachine ( 'StateMachine3' , helloTable , [ 'arn:aws:states:::aws-sdk:dynamodb:updateItem' , 'arn:aws:states:::aws-sdk:dynamodb:putItem' ] ) ,
561
+ myStateMachine4 : genStateMachine ( 'StateMachine4' , worldTable , [ 'arn:aws:states:::aws-sdk:dynamodb:updateItem.waitForTaskToken' , 'arn:aws:states:::aws-sdk:dynamodb:putItem.waitForTaskToken' ] ) ,
560
562
} ,
561
563
} ;
562
564
@@ -565,8 +567,10 @@ describe('#compileIamRole', () => {
565
567
. provider . compiledCloudFormationTemplate . Resources ;
566
568
const policy1 = resources . StateMachine1Role . Properties . Policies [ 0 ] ;
567
569
const policy2 = resources . StateMachine2Role . Properties . Policies [ 0 ] ;
570
+ const policy3 = resources . StateMachine3Role . Properties . Policies [ 0 ] ;
571
+ const policy4 = resources . StateMachine4Role . Properties . Policies [ 0 ] ;
568
572
569
- [ policy1 , policy2 ] . forEach ( ( policy ) => {
573
+ [ policy1 , policy2 , policy3 , policy4 ] . forEach ( ( policy ) => {
570
574
expect ( policy . PolicyDocument . Statement [ 0 ] . Action )
571
575
. to . be . deep . equal ( [
572
576
'dynamodb:UpdateItem' ,
@@ -580,6 +584,10 @@ describe('#compileIamRole', () => {
580
584
. to . be . deep . equal ( [ helloTableArn ] ) ;
581
585
expect ( policy2 . PolicyDocument . Statement [ 0 ] . Resource )
582
586
. to . be . deep . equal ( [ worldTableArn ] ) ;
587
+ expect ( policy3 . PolicyDocument . Statement [ 0 ] . Resource )
588
+ . to . be . deep . equal ( [ helloTableArn ] ) ;
589
+ expect ( policy4 . PolicyDocument . Statement [ 0 ] . Resource )
590
+ . to . be . deep . equal ( [ worldTableArn ] ) ;
583
591
} ) ;
584
592
585
593
it ( 'should give dynamodb permission for table name imported from external stack' , ( ) => {
@@ -598,22 +606,22 @@ describe('#compileIamRole', () => {
598
606
] ,
599
607
} ;
600
608
601
- const genStateMachine = ( id , tableName ) => ( {
609
+ const genStateMachine = ( id , tableName , resources ) => ( {
602
610
id,
603
611
definition : {
604
612
StartAt : 'A' ,
605
613
States : {
606
614
A : {
607
615
Type : 'Task' ,
608
- Resource : 'arn:aws:states:::dynamodb:updateItem' ,
616
+ Resource : resources [ 0 ] ,
609
617
Parameters : {
610
618
TableName : tableName ,
611
619
} ,
612
620
Next : 'B' ,
613
621
} ,
614
622
B : {
615
623
Type : 'Task' ,
616
- Resource : 'arn:aws:states:::dynamodb:putItem' ,
624
+ Resource : resources [ 1 ] ,
617
625
Parameters : {
618
626
TableName : tableName ,
619
627
} ,
@@ -641,8 +649,10 @@ describe('#compileIamRole', () => {
641
649
642
650
serverless . service . stepFunctions = {
643
651
stateMachines : {
644
- myStateMachine1 : genStateMachine ( 'StateMachine1' , externalHelloTable ) ,
645
- myStateMachine2 : genStateMachine ( 'StateMachine2' , externalWorldTable ) ,
652
+ myStateMachine1 : genStateMachine ( 'StateMachine1' , externalHelloTable , [ 'arn:aws:states:::dynamodb:updateItem' , 'arn:aws:states:::dynamodb:putItem' ] ) ,
653
+ myStateMachine2 : genStateMachine ( 'StateMachine2' , externalWorldTable , [ 'arn:aws:states:::dynamodb:updateItem' , 'arn:aws:states:::dynamodb:putItem' ] ) ,
654
+ myStateMachine3 : genStateMachine ( 'StateMachine3' , externalHelloTable , [ 'arn:aws:states:::aws-sdk:dynamodb:updateItem' , 'arn:aws:states:::aws-sdk:dynamodb:putItem' ] ) ,
655
+ myStateMachine4 : genStateMachine ( 'StateMachine4' , externalWorldTable , [ 'arn:aws:states:::aws-sdk:dynamodb:updateItem.waitForTaskToken' , 'arn:aws:states:::aws-sdk:dynamodb:putItem.waitForTaskToken' ] ) ,
646
656
} ,
647
657
} ;
648
658
@@ -652,8 +662,10 @@ describe('#compileIamRole', () => {
652
662
. provider . compiledCloudFormationTemplate . Resources ;
653
663
const policy1 = resources . StateMachine1Role . Properties . Policies [ 0 ] ;
654
664
const policy2 = resources . StateMachine2Role . Properties . Policies [ 0 ] ;
665
+ const policy3 = resources . StateMachine3Role . Properties . Policies [ 0 ] ;
666
+ const policy4 = resources . StateMachine4Role . Properties . Policies [ 0 ] ;
655
667
656
- [ policy1 , policy2 ] . forEach ( ( policy ) => {
668
+ [ policy1 , policy2 , policy3 , policy4 ] . forEach ( ( policy ) => {
657
669
expect ( policy . PolicyDocument . Statement [ 0 ] . Action )
658
670
. to . be . deep . equal ( [
659
671
'dynamodb:UpdateItem' ,
@@ -667,6 +679,10 @@ describe('#compileIamRole', () => {
667
679
. to . be . deep . equal ( [ helloTableArn ] ) ;
668
680
expect ( policy2 . PolicyDocument . Statement [ 0 ] . Resource )
669
681
. to . be . deep . equal ( [ worldTableArn ] ) ;
682
+ expect ( policy3 . PolicyDocument . Statement [ 0 ] . Resource )
683
+ . to . be . deep . equal ( [ helloTableArn ] ) ;
684
+ expect ( policy4 . PolicyDocument . Statement [ 0 ] . Resource )
685
+ . to . be . deep . equal ( [ worldTableArn ] ) ;
670
686
} ) ;
671
687
672
688
it ( 'should give dynamodb permission to * whenever TableName.$ is seen' , ( ) => {
0 commit comments