]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/python |
2 | ||
3 | import boto3 | |
4 | import sys | |
5 | ||
6 | if len(sys.argv) != 4: | |
7 | print 'Usage: ' + sys.argv[0] + ' <bucket> <topic ARN> <notification Id>' | |
8 | sys.exit(1) | |
9 | ||
10 | # bucket name as first argument | |
11 | bucketname = sys.argv[1] | |
12 | # topic ARN as second argument | |
13 | topic_arn = sys.argv[2] | |
14 | # notification id as third argument | |
15 | notification_id = sys.argv[3] | |
16 | ||
17 | # endpoint and keys from vstart | |
18 | endpoint = 'http://127.0.0.1:8000' | |
19 | access_key='0555b35654ad1656d804' | |
20 | secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' | |
21 | ||
22 | client = boto3.client('s3', | |
23 | endpoint_url=endpoint, | |
24 | aws_access_key_id=access_key, | |
25 | aws_secret_access_key=secret_key) | |
26 | ||
27 | # regex filter on the object name and metadata based filtering are extension to AWS S3 API | |
28 | # bucket and topic should be created beforehand | |
29 | ||
30 | topic_conf_list = [{'Id': notification_id, | |
31 | 'TopicArn': topic_arn, | |
32 | 'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'], | |
33 | 'Filter': { | |
34 | 'Metadata': { | |
35 | 'FilterRules': [{'Name': 'x-amz-meta-foo', 'Value': 'bar'}, | |
36 | {'Name': 'x-amz-meta-hello', 'Value': 'world'}] | |
37 | }, | |
38 | 'Tags': { | |
39 | 'FilterRules': [{'Name': 'foo', 'Value': 'bar'}, | |
40 | {'Name': 'hello', 'Value': 'world'}] | |
41 | }, | |
42 | 'Key': { | |
43 | 'FilterRules': [{'Name': 'regex', 'Value': '([a-z]+)'}] | |
44 | } | |
45 | }}] | |
46 | ||
47 | print client.put_bucket_notification_configuration(Bucket=bucketname, | |
48 | NotificationConfiguration={'TopicConfigurations': topic_conf_list}) |