7 print('Usage: ' + sys
.argv
[0] + ' <bucket> <topic ARN> <notification Id>')
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]
17 # endpoint and keys from vstart
18 endpoint
= 'http://127.0.0.1:8000'
19 access_key
='0555b35654ad1656d804'
20 secret_key
='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
22 client
= boto3
.client('s3',
23 endpoint_url
=endpoint
,
24 aws_access_key_id
=access_key
,
25 aws_secret_access_key
=secret_key
)
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
30 topic_conf_list
= [{'Id': notification_id
,
31 'TopicArn': topic_arn
,
32 'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'],
35 'FilterRules': [{'Name': 'x-amz-meta-foo', 'Value': 'bar'},
36 {'Name': 'x-amz-meta-hello', 'Value': 'world'}]
39 'FilterRules': [{'Name': 'foo', 'Value': 'bar'},
40 {'Name': 'hello', 'Value': 'world'}]
43 'FilterRules': [{'Name': 'regex', 'Value': '([a-z]+)'}]
47 print(client
.put_bucket_notification_configuration(Bucket
=bucketname
,
48 NotificationConfiguration
={'TopicConfigurations': topic_conf_list
}))