@@ -1494,8 +1494,9 @@ describe('#compileIamRole', () => {
1494
1494
} ) ;
1495
1495
1496
1496
it ( 'should give s3:GetObject permission for only objects referenced by state machine with ItemReader' , ( ) => {
1497
+ const hello = 'hello.txt' ;
1498
+ const world = 'world.txt' ;
1497
1499
const testBucket = 'test-bucket' ;
1498
- const testKey = 'test-key' ;
1499
1500
1500
1501
const genStateMachine = ( id , lambdaArn , bucket , key ) => ( {
1501
1502
id,
@@ -1517,8 +1518,8 @@ describe('#compileIamRole', () => {
1517
1518
ItemReader : {
1518
1519
Resource : 'arn:aws:states:::s3:getObject' ,
1519
1520
Parameters : {
1520
- ' Bucket.$' : bucket ,
1521
- ' Key.$' : key ,
1521
+ Bucket : bucket ,
1522
+ Key : key ,
1522
1523
} ,
1523
1524
} ,
1524
1525
End : true ,
@@ -1530,9 +1531,9 @@ describe('#compileIamRole', () => {
1530
1531
serverless . service . stepFunctions = {
1531
1532
stateMachines : {
1532
1533
myStateMachine1 : genStateMachine ( 'StateMachine1' ,
1533
- 'arn:aws:lambda:us-west-2:1234567890:function:foo' , '$. testBucket' , '$.testKey' ) ,
1534
+ 'arn:aws:lambda:us-west-2:1234567890:function:foo' , testBucket , hello ) ,
1534
1535
myStateMachine2 : genStateMachine ( 'StateMachine2' ,
1535
- 'arn:aws:lambda:us-west-2:1234567890:function:foo' , testBucket , testKey ) ,
1536
+ 'arn:aws:lambda:us-west-2:1234567890:function:foo' , testBucket , world ) ,
1536
1537
} ,
1537
1538
} ;
1538
1539
@@ -1542,9 +1543,80 @@ describe('#compileIamRole', () => {
1542
1543
const policy1 = resources . StateMachine1Role . Properties . Policies [ 0 ] ;
1543
1544
const policy2 = resources . StateMachine2Role . Properties . Policies [ 0 ] ;
1544
1545
expect ( policy1 . PolicyDocument . Statement [ 1 ] . Resource )
1545
- . to . be . deep . equal ( '*' ) ;
1546
+ . to . be . deep . equal ( [ `arn:aws:s3::: ${ testBucket } / ${ hello } ` ] ) ;
1546
1547
expect ( policy2 . PolicyDocument . Statement [ 1 ] . Resource )
1547
- . to . be . deep . equal ( [ `arn:aws:s3:::${ testBucket } /${ testKey } ` ] ) ;
1548
+ . to . be . deep . equal ( [ `arn:aws:s3:::${ testBucket } /${ world } ` ] ) ;
1549
+ } ) ;
1550
+
1551
+ it ( 'should give s3:GetObject permission to * when Bucket.$ and Key.$ are seen on ItemReader' , ( ) => {
1552
+ const genStateMachine = ( id , lambdaArn ) => ( {
1553
+ id,
1554
+ definition : {
1555
+ StartAt : 'A' ,
1556
+ States : {
1557
+ A : {
1558
+ Type : 'Map' ,
1559
+ ItemProcessor : {
1560
+ StartAt : 'B' ,
1561
+ States : {
1562
+ B : {
1563
+ Type : 'Task' ,
1564
+ Resource : lambdaArn ,
1565
+ End : true ,
1566
+ } ,
1567
+ } ,
1568
+ } ,
1569
+ ItemReader : {
1570
+ Resource : 'arn:aws:states:::s3:getObject' ,
1571
+ Parameters : {
1572
+ Bucket : 'test-bucket' ,
1573
+ Key : 'test-key' ,
1574
+ } ,
1575
+ } ,
1576
+ Next : 'C' ,
1577
+ } ,
1578
+ C : {
1579
+ Type : 'Map' ,
1580
+ ItemProcessor : {
1581
+ StartAt : 'D' ,
1582
+ States : {
1583
+ D : {
1584
+ Type : 'Task' ,
1585
+ Resource : lambdaArn ,
1586
+ End : true ,
1587
+ } ,
1588
+ } ,
1589
+ } ,
1590
+ ItemReader : {
1591
+ Resource : 'arn:aws:states:::s3:getObject' ,
1592
+ Parameters : {
1593
+ 'Bucket.$' : '$.testBucket' ,
1594
+ 'Key.$' : '$.key' ,
1595
+ } ,
1596
+ } ,
1597
+ End : true ,
1598
+ } ,
1599
+ } ,
1600
+ } ,
1601
+ } ) ;
1602
+
1603
+ serverless . service . stepFunctions = {
1604
+ stateMachines : {
1605
+ myStateMachine1 : genStateMachine ( 'StateMachine1' ,
1606
+ 'arn:aws:lambda:us-west-2:1234567890:function:foo' ) ,
1607
+ } ,
1608
+ } ;
1609
+
1610
+ serverlessStepFunctions . compileIamRole ( ) ;
1611
+ const resources = serverlessStepFunctions . serverless . service
1612
+ . provider . compiledCloudFormationTemplate . Resources ;
1613
+ const policy1 = resources . StateMachine1Role . Properties . Policies [ 0 ] ;
1614
+
1615
+ // even though some tasks target specific topic ARNs, other states use Bucket.$
1616
+ // and Key.$ so we need to give broad permissions to be able to get any
1617
+ // table and key the input specifies
1618
+ expect ( policy1 . PolicyDocument . Statement [ 1 ] . Resource )
1619
+ . to . be . deep . equal ( '*' ) ;
1548
1620
} ) ;
1549
1621
1550
1622
it ( 'should not generate any permissions for Task states not yet supported' , ( ) => {
0 commit comments