Skip to content

Commit

Permalink
Fix issue concon121#5
Browse files Browse the repository at this point in the history
  • Loading branch information
ericballetbaz committed Sep 15, 2020
1 parent 23e5895 commit e366edf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ module.exports = {
fixLogGroups(args) {
var cft = this.serverless.service.provider.compiledCloudFormationTemplate
var role = cft.Resources.IamRoleLambdaExecution
for (var policy of role.Properties.Policies) {
for (var statement of policy.PolicyDocument.Statement.filter((s) => (s.Action.includes("logs:CreateLogStream") || s.Action.includes("logs:PutLogEvents")))) {
statement.Resource = statement.Resource.filter(function(value, index, arr) {
return Object.values(value).filter(function (v) { return v.includes("log-group") }).length === 0;
});
if (role) {
for (var policy of role.Properties.Policies) {
for (var statement of policy.PolicyDocument.Statement.filter((s) => (s.Action.includes("logs:CreateLogStream") || s.Action.includes("logs:PutLogEvents")))) {
statement.Resource = statement.Resource.filter(function(value, index, arr) {
return Object.values(value).filter(function (v) { return v.includes("log-group") }).length === 0;
});

for (var resource of Object.keys(cft.Resources).filter((r) => r.includes("LogGroup"))) {
statement.Resource.push({
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${" + resource + "}:*" + (statement.Action.includes("logs:PutLogEvents") ? ":*" : "")
})
for (var resource of Object.keys(cft.Resources).filter((r) => r.includes("LogGroup"))) {
statement.Resource.push({
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${" + resource + "}:*" + (statement.Action.includes("logs:PutLogEvents") ? ":*" : "")
})
}
}
}
}
Expand Down

0 comments on commit e366edf

Please sign in to comment.