# Buggy code
def factory(self, data, manager=None):
    """Factory func for filters.

    data - policy config for filters
    manager - resource type manager (ec2, s3, etc)
    """

    # Make the syntax a little nicer for common cases.
    if isinstance(data, dict) and len(data) == 1 and "type" not in data:
        op = list(data.keys())[0]
        if op == "or":
            return Or(data, self, manager)
        elif op == "and":
            return And(data, self, manager)
        elif op == "not":
            return Not(data, self, manager)
        return ValueFilter(data, manager)
    if isinstance(data, str):
        filter_type = data
        data = {"type": data}
    else:
        filter_type = data.get("type")
    if not filter_type:
        raise PolicyValidationError("%s Invalid Filter %s" % (self.plugin_type, data))
    filter_class = self.get(filter_type)
    if filter_class is not None:
        return filter_class(data, manager)
    else:
        raise PolicyValidationError(
            "%s Invalid filter type %s" % (self.plugin_type, data)
        )


# Traceback (KeyError)
$ custodian run -d -v -s out -p run-asg-auto-tag-creator ./auto-tag-creator.yaml
2020-05-06 15:47:07,205: custodian.commands:DEBUG Loaded file ./auto-tag-creator.yaml. Contains 11 policies
2020-05-06 15:47:07,223: custodian.aws:DEBUG using default region:us-west-2 from boto
2020-05-06 15:47:07,778: custodian.commands:ERROR Error while executing policy run-asg-auto-tag-creator, continuing
Traceback (most recent call last):
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/commands.py", line 281, in run
policy()
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/policy.py", line 1056, in __call__
resources = PullMode(self).run()
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/policy.py", line 279, in run
if not self.policy.is_runnable():
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/policy.py", line 906, in is_runnable
return self.conditions.evaluate(event)
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/policy.py", line 843, in evaluate
state = all([f.process([policy_vars], event) for f in self.filters])
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/policy.py", line 843, in <listcomp>
state = all([f.process([policy_vars], event) for f in self.filters])
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/filters/core.py", line 299, in process
return self.process_set(resources, event)
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/filters/core.py", line 314, in process_set
resource_map = {r[rtype_id]: r for r in resources}
File "/Users/tstansell/.local/c7n/lib/python3.7/site-packages/c7n/filters/core.py", line 314, in <dictcomp>
resource_map = {r[rtype_id]: r for r in resources}
KeyError: 'AutoScalingGroupName'

# Fixed code
def factory(self, data, manager=None):
    """Factory func for filters.

    data - policy config for filters
    manager - resource type manager (ec2, s3, etc)
    """

    # Make the syntax a little nicer for common cases.
    if isinstance(data, dict) and len(data) == 1 and "type" not in data:
        op = list(data.keys())[0]
        if op == "or":
            return self["or"](data, self, manager)
        elif op == "and":
            return self["and"](data, self, manager)
        elif op == "not":
            return self["not"](data, self, manager)
        return ValueFilter(data, manager)
    if isinstance(data, str):
        filter_type = data
        data = {"type": data}
    else:
        filter_type = data.get("type")
    if not filter_type:
        raise PolicyValidationError("%s Invalid Filter %s" % (self.plugin_type, data))
    filter_class = self.get(filter_type)
    if filter_class is not None:
        return filter_class(data, manager)
    else:
        raise PolicyValidationError(
            "%s Invalid filter type %s" % (self.plugin_type, data)
        )