Skip to content

Commit ef0c149

Browse files
feat: intrinsic funcs for dynamodb iam
1 parent b7968a5 commit ef0c149

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/deploy/stepFunctions/compileIamRole.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ function getSnsPermissions(serverless, state) {
6565
}
6666

6767
function getDynamoDBArn(tableName) {
68+
if (isIntrinsic(tableName) && tableName.Ref) {
69+
// most likely we'll see a { Ref: LogicalId }, which we need to map to
70+
// { Fn::GetAtt: [ LogicalId, Arn ] } to get the ARN
71+
return {
72+
'Fn::GetAtt': [tableName.Ref, 'Arn'],
73+
};
74+
}
75+
6876
return {
6977
'Fn::Join': [
7078
':',

lib/deploy/stepFunctions/compileIamRole.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,16 @@ describe('#compileIamRole', () => {
938938
},
939939
MessageBody: 'This is a static message',
940940
},
941+
Next: 'DynamoDB',
942+
},
943+
DynamoDB: {
944+
Type: 'Task',
945+
Resource: 'arn:aws:states:::dynamodb:putItem',
946+
Parameters: {
947+
TableName: {
948+
Ref: 'MyTable',
949+
},
950+
},
941951
Next: 'Parallel',
942952
},
943953
Parallel: {
@@ -971,14 +981,22 @@ describe('#compileIamRole', () => {
971981
.Properties.Policies[0];
972982

973983
const statements = policy.PolicyDocument.Statement;
984+
974985
const lambdaPermissions = statements.find(x => x.Action[0] === 'lambda:InvokeFunction');
975986
expect(lambdaPermissions.Resource).to.be.deep.equal([
976987
{ Ref: 'MyFunction' }, { Ref: 'MyFunction2' }]);
988+
977989
const snsPermissions = statements.find(x => x.Action[0] === 'sns:Publish');
978990
expect(snsPermissions.Resource).to.be.deep.equal([{ Ref: 'MyTopic' }]);
991+
979992
const sqsPermissions = statements.find(x => x.Action[0] === 'sqs:SendMessage');
980993
expect(sqsPermissions.Resource).to.be.deep.equal([{
981994
'Fn::GetAtt': ['MyQueue', 'Arn'],
982995
}]);
996+
997+
const dynamodbPermissions = statements.find(x => x.Action[0] === 'dynamodb:PutItem');
998+
expect(dynamodbPermissions.Resource).to.be.deep.equal([{
999+
'Fn::GetAtt': ['MyTable', 'Arn'],
1000+
}]);
9831001
});
9841002
});

0 commit comments

Comments
 (0)