Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prefix/suffix filters on S3 #75

Merged
merged 4 commits into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion kappa/event_source/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ def add(self, function):
{
'Id': self._make_notification_id(function.name),
'Events': [e for e in self._config['events']],
'LambdaFunctionArn': function.arn,
'LambdaFunctionArn': '%s:%s' % (function.arn, function._context.environment),
}
]
}

# Add S3 key filters
if 'key_filters' in self._config:
filters_spec = { 'Key' : { 'FilterRules' : [] } }
for filter in self._config['key_filters']:
if 'type' in filter and 'value' in filter and filter['type'] in ('prefix', 'suffix'):
rule = { 'Name' : filter['type'], 'Value' : filter['value'] }
filters_spec['Key']['FilterRules'].append(rule)
notification_spec['LambdaFunctionConfigurations'][0]['Filter'] = filters_spec

try:
response = self._s3.call(
'put_bucket_notification_configuration',
Expand Down
5 changes: 5 additions & 0 deletions samples/s3/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ lambda:
arn: arn:aws:s3:::test-1245812163
events:
- s3:ObjectCreated:*
key_filters:
- type: prefix
value: someprefix/
- type: suffix
value: .zip
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run_setup():
author='Mitch Garnaat',
author_email='mitch@garnaat.com',
license='Apache License 2.0',
packages=['kappa', 'kappa.scripts'],
packages=['kappa', 'kappa.scripts', 'kappa.event_source'],
package_data={'kappa': ['_version']},
package_dir={'kappa': 'kappa'},
entry_points="""
Expand Down