Repository: cloud-custodian/cloud-custodian

Issue:
Lambda error processing event-rule resource
I'm facing an error when using the aws.event-rule resource in cloudtrail mode:
the lambda function exits with this error after getting the resource_id:
AttributeError: type object 'resource_type' has no attribute 'filter_type'

Can you help me making this work ?

Here is the detailed stacktrace:
````
type object 'resource_type' has no attribute 'filter_type': AttributeError
Traceback (most recent call last):
File "/var/task/custodian_policy.py", line 4, in run
return handler.dispatch_event(event, context)
File "/var/task/c7n/handler.py", line 91, in dispatch_event
p.push(event, context)
File "/var/task/c7n/policy.py", line 776, in push
return mode.run(event, lambda_ctx)
File "/var/task/c7n/policy.py", line 441, in run
resources = self.resolve_resources(event)
File "/var/task/c7n/policy.py", line 418, in resolve_resources
resources = self.policy.resource_manager.get_resources(resource_ids)
File "/var/task/c7n/query.py", line 441, in get_resources
resources = self.source.get_resources(ids)
File "/var/task/c7n/query.py", line 212, in get_resources
return self.query.get(self.manager, ids)
File "/var/task/c7n/query.py", line 93, in get
if m.filter_type == 'list':
AttributeError: type object 'resource_type' has no attribute 'filter_type'

````

Here is the policy i'm using:
```
policies:
  - name: tlogs-modify-prefixrules
    resource: aws.event-rule
    filters:
      - or: 
        - type: event
          key: detail.requestParameters.name
          value: "prefix-.*"
          op: Regex
        - type: value
          key: detail.requestParameters.rule
          value: "prefix-.*"
          op: Regex
    mode:
      function-prefix: "prefix-"
      type: cloudtrail
      role: arn:aws:iam::{account_id}:role/prefix/prefix_custodian_core
      events:
        - source: events.amazonaws.com
          event: DeleteRule
          ids: requestParameters.name
        - source: events.amazonaws.com
          event: DisableRule
          ids: requestParameters.name
        - source: events.amazonaws.com
          event: RemoveTargets
          ids: requestParameters.name
        - source: events.amazonaws.com
          event: PutRule
          ids: requestParameters.name
    description: |
          Alerts when prefix event-rules are modified    
    actions:
      - type: invoke-lambda
        function: prefix-lambda-notifier
```



Discussion:

Resolving patch:
diff --git a/c7n/resources/cw.py b/c7n/resources/cw.py
--- a/c7n/resources/cw.py
+++ b/c7n/resources/cw.py
@@ -17,7 +17,7 @@
 from datetime import datetime, timedelta
 
 from c7n.actions import BaseAction
-from c7n.filters import Filter
+from c7n.filters import Filter, MetricsFilter
 from c7n.filters.iamaccess import CrossAccountAccessFilter
 from c7n.query import QueryResourceManager, ChildResourceManager
 from c7n.manager import resources
@@ -89,8 +89,15 @@ class resource_type(object):
         name = "Name"
         id = "Name"
         filter_name = "NamePrefix"
-        filer_type = "scalar"
-        dimension = "RuleName"
+        filter_type = "scalar"
+        dimension = None
+
+
+@EventRule.filter_registry.register('metrics')
+class EventRuleMetrics(MetricsFilter):
+
+    def get_dimensions(self, resource):
+        return [{'Name': 'RuleName', 'Value': resource['Name']}]
 
 
 @resources.register('event-rule-target')
@@ -281,7 +288,7 @@ def process(self, resources, event=None):
         client = local_session(self.manager.session_factory).client('logs')
         accounts = self.get_accounts()
         results = []
-        with self.executor_factory(max_workers=2) as w:
+        with self.executor_factory(max_workers=1) as w:
             futures = []
             for rset in chunks(resources, 50):
                 futures.append(


Test patch: