From e366edf871bd0bfd201c0ccf801a04f62a90dbbd Mon Sep 17 00:00:00 2001 From: "Eric Ballet Baz 22594539+eballetbaz@users.noreply.github.com" Date: Tue, 15 Sep 2020 15:07:50 +0200 Subject: [PATCH] Fix issue https://github.com/concon121/serverless-plugin-aws-resource-names/issues/5 --- naming.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/naming.js b/naming.js index 0013fce..4fd281b 100644 --- a/naming.js +++ b/naming.js @@ -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") ? ":*" : "") + }) + } } } }