Matteo Sessa

Add support for prefix/suffix filters on S3

...@@ -41,6 +41,16 @@ class S3EventSource(kappa.event_source.base.EventSource): ...@@ -41,6 +41,16 @@ class S3EventSource(kappa.event_source.base.EventSource):
41 } 41 }
42 ] 42 ]
43 } 43 }
44 +
45 + # Add S3 key filters
46 + if 'key_filters' in self._config:
47 + filters_spec = { 'Key' : { 'FilterRules' : [] } }
48 + for filter in self._config['key_filters']:
49 + if 'type' in filter and 'value' in filter and filter['type'] in ('prefix', 'suffix'):
50 + rule = { 'Name' : filter['type'], 'Value' : filter['value'] }
51 + filters_spec['Key']['FilterRules'].append(rule)
52 + notification_spec['LambdaFunctionConfigurations'][0]['Filter'] = filters_spec
53 +
44 try: 54 try:
45 response = self._s3.call( 55 response = self._s3.call(
46 'put_bucket_notification_configuration', 56 'put_bucket_notification_configuration',
......
...@@ -34,3 +34,8 @@ lambda: ...@@ -34,3 +34,8 @@ lambda:
34 arn: arn:aws:s3:::test-1245812163 34 arn: arn:aws:s3:::test-1245812163
35 events: 35 events:
36 - s3:ObjectCreated:* 36 - s3:ObjectCreated:*
37 + key_filters:
38 + - type: prefix
39 + value: someprefix/
40 + - type: suffix
41 + value: .zip
......