Committed by
GitHub
Merge pull request #75 from cotdsa/develop
Add support for prefix/suffix filters on S3
Showing
3 changed files
with
17 additions
and
2 deletions
... | @@ -37,10 +37,20 @@ class S3EventSource(kappa.event_source.base.EventSource): | ... | @@ -37,10 +37,20 @@ class S3EventSource(kappa.event_source.base.EventSource): |
37 | { | 37 | { |
38 | 'Id': self._make_notification_id(function.name), | 38 | 'Id': self._make_notification_id(function.name), |
39 | 'Events': [e for e in self._config['events']], | 39 | 'Events': [e for e in self._config['events']], |
40 | - 'LambdaFunctionArn': function.arn, | 40 | + 'LambdaFunctionArn': '%s:%s' % (function.arn, function._context.environment), |
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 | ... | ... |
... | @@ -24,7 +24,7 @@ def run_setup(): | ... | @@ -24,7 +24,7 @@ def run_setup(): |
24 | author='Mitch Garnaat', | 24 | author='Mitch Garnaat', |
25 | author_email='mitch@garnaat.com', | 25 | author_email='mitch@garnaat.com', |
26 | license='Apache License 2.0', | 26 | license='Apache License 2.0', |
27 | - packages=['kappa', 'kappa.scripts'], | 27 | + packages=['kappa', 'kappa.scripts', 'kappa.event_source'], |
28 | package_data={'kappa': ['_version']}, | 28 | package_data={'kappa': ['_version']}, |
29 | package_dir={'kappa': 'kappa'}, | 29 | package_dir={'kappa': 'kappa'}, |
30 | entry_points=""" | 30 | entry_points=""" | ... | ... |
-
Please register or login to post a comment