Skip to content

Commit 40c37ec

Browse files
authored
Merge pull request #5 from AntonBazhal/concurrency-fix
Switched to a sequential creation of permission resorces for the same…
2 parents 4032046 + 0e6f6b1 commit 40c37ec

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

Diff for: add-permissions.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ module.exports = class AwsAddLambdaAccountPermissions {
3838

3939
const functionLogicalId = this.provider.naming.getLambdaLogicalId(functionName);
4040

41-
functionAllowAccess.forEach(principal => {
41+
functionAllowAccess.reduce((previousResourceName, principal) => {
4242
principal = principal.toString();
43-
const resourceName = principal.replace(/\b\w/g, l => l.toUpperCase()).replace(/[_\W]+/g, "");
44-
resources.Resources[`${functionLogicalId}PermitInvokeFrom${resourceName}`] = {
43+
const principalName = principal.replace(/\b\w/g, l => l.toUpperCase()).replace(/[_\W]+/g, "");
44+
const resourceName = `${functionLogicalId}PermitInvokeFrom${principalName}`;
45+
const resource = {
4546
Type: 'AWS::Lambda::Permission',
4647
Properties: {
4748
Action: 'lambda:InvokeFunction',
@@ -51,7 +52,14 @@ module.exports = class AwsAddLambdaAccountPermissions {
5152
Principal: principal
5253
}
5354
};
54-
});
55+
56+
if (previousResourceName) {
57+
resource.DependsOn = previousResourceName;
58+
}
59+
60+
resources.Resources[resourceName] = resource;
61+
return resourceName;
62+
}, null);
5563
});
5664
}
5765

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-plugin-lambda-account-access",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"engines": {
55
"node": ">=4.0"
66
},

Diff for: test/add-permissions-tests.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ describe('serverless-plugin-lambda-account-access', function() {
157157
'Fn::GetAtt': [ 'Function1LambdaFunction', 'Arn' ],
158158
},
159159
'Principal': '222222222222'
160-
}
160+
},
161+
'DependsOn': 'Function1LambdaFunctionPermitInvokeFrom111111111111'
161162
},
162163
'Function2LambdaFunctionPermitInvokeFrom111111111111': {
163164
'Type': 'AWS::Lambda::Permission',
@@ -177,7 +178,8 @@ describe('serverless-plugin-lambda-account-access', function() {
177178
'Fn::GetAtt': [ 'Function2LambdaFunction', 'Arn' ],
178179
},
179180
'Principal': '222222222222'
180-
}
181+
},
182+
'DependsOn': 'Function2LambdaFunctionPermitInvokeFrom111111111111'
181183
}
182184
});
183185
});
@@ -215,7 +217,8 @@ describe('serverless-plugin-lambda-account-access', function() {
215217
'Fn::GetAtt': [ 'Function2LambdaFunction', 'Arn' ],
216218
},
217219
'Principal': '222222222222'
218-
}
220+
},
221+
'DependsOn': 'Function2LambdaFunctionPermitInvokeFrom111111111111'
219222
}
220223
});
221224
});
@@ -253,7 +256,8 @@ describe('serverless-plugin-lambda-account-access', function() {
253256
'Fn::GetAtt': [ 'Function2LambdaFunction', 'Arn' ],
254257
},
255258
'Principal': '222222222222'
256-
}
259+
},
260+
'DependsOn': 'Function2LambdaFunctionPermitInvokeFrom111111111111'
257261
}
258262
});
259263
});
@@ -291,7 +295,8 @@ describe('serverless-plugin-lambda-account-access', function() {
291295
'Fn::GetAtt': [ 'Function1LambdaFunction', 'Arn' ],
292296
},
293297
'Principal': '444444444444'
294-
}
298+
},
299+
'DependsOn': 'Function1LambdaFunctionPermitInvokeFrom333333333333'
295300
},
296301
'Function2LambdaFunctionPermitInvokeFrom111111111111': {
297302
'Type': 'AWS::Lambda::Permission',
@@ -311,7 +316,8 @@ describe('serverless-plugin-lambda-account-access', function() {
311316
'Fn::GetAtt': [ 'Function2LambdaFunction', 'Arn' ],
312317
},
313318
'Principal': '222222222222'
314-
}
319+
},
320+
'DependsOn': 'Function2LambdaFunctionPermitInvokeFrom111111111111'
315321
}
316322
});
317323
});

0 commit comments

Comments
 (0)