@@ -1046,6 +1046,47 @@ describe('#compileIamRole', () => {
10461046 expectDenyAllPolicy ( policy ) ;
10471047 } ) ;
10481048
1049+ it ( 'should give s3:GetObject permission for only objects referenced by state machine' , ( ) => {
1050+ const hello = 'hello.txt' ;
1051+ const world = 'world.txt' ;
1052+ const testBucket = 'test-bucket' ;
1053+
1054+ const genStateMachine = ( id , bucket , key ) => ( {
1055+ id,
1056+ definition : {
1057+ StartAt : 'A' ,
1058+ States : {
1059+ A : {
1060+ Type : 'Task' ,
1061+ Resource : 'arn:aws:states:::aws-sdk:s3:getObject' ,
1062+ Parameters : {
1063+ Bucket : bucket ,
1064+ Key : key ,
1065+ } ,
1066+ End : true ,
1067+ } ,
1068+ } ,
1069+ } ,
1070+ } ) ;
1071+
1072+ serverless . service . stepFunctions = {
1073+ stateMachines : {
1074+ myStateMachine1 : genStateMachine ( 'StateMachine1' , testBucket , hello ) ,
1075+ myStateMachine2 : genStateMachine ( 'StateMachine2' , testBucket , world ) ,
1076+ } ,
1077+ } ;
1078+
1079+ serverlessStepFunctions . compileIamRole ( ) ;
1080+ const resources = serverlessStepFunctions . serverless . service
1081+ . provider . compiledCloudFormationTemplate . Resources ;
1082+ const policy1 = resources . StateMachine1Role . Properties . Policies [ 0 ] ;
1083+ const policy2 = resources . StateMachine2Role . Properties . Policies [ 0 ] ;
1084+ expect ( policy1 . PolicyDocument . Statement [ 0 ] . Resource )
1085+ . to . be . deep . equal ( [ `arn:aws:s3:::${ testBucket } /${ hello } ` ] ) ;
1086+ expect ( policy2 . PolicyDocument . Statement [ 0 ] . Resource )
1087+ . to . be . deep . equal ( [ `arn:aws:s3:::${ testBucket } /${ world } ` ] ) ;
1088+ } ) ;
1089+
10491090 it ( 'should not generate any permissions for Task states not yet supported' , ( ) => {
10501091 const genStateMachine = id => ( {
10511092 id,
0 commit comments