in shared/lint/rules/custom_rules.py [0:0]
def match(self, cfn):
"""
Match functions that don't have a log group
"""
matches = []
functions = cfn.get_resources("AWS::Lambda::Function")
log_groups = cfn.get_resources("AWS::Logs::LogGroup")
known = []
# Scan log groups for resource names
for resource in log_groups.values():
# This use an autogenerated log group name
if "LogGroupName" not in resource.get("Properties"):
continue
log_group_name = resource.get("Properties").get("LogGroupName")
# This doesn't have a !Sub transformation
if not isinstance(log_group_name, dict) or "Fn::Sub" not in log_group_name:
continue
match = re.search(r"\${(?P<func>[^}]+)}", log_group_name["Fn::Sub"])
if match is not None:
known.append(match["func"])
# Scan functions against log groups
for function in functions.keys():
if function not in known:
matches.append(RuleMatch(
["Resources", function],
self._message.format(function)
))
return matches