]> git.proxmox.com Git - ceph.git/blame - ceph/examples/boto3/notification_filters.py
import ceph 15.2.14
[ceph.git] / ceph / examples / boto3 / notification_filters.py
CommitLineData
9f95a23c
TL
1#!/usr/bin/python
2
3import boto3
4import sys
5
6if len(sys.argv) != 4:
ec96510d 7 print('Usage: ' + sys.argv[0] + ' <bucket> <topic ARN> <notification Id>')
9f95a23c
TL
8 sys.exit(1)
9
10# bucket name as first argument
11bucketname = sys.argv[1]
12# topic ARN as second argument
13topic_arn = sys.argv[2]
14# notification id as third argument
15notification_id = sys.argv[3]
16
17# endpoint and keys from vstart
18endpoint = 'http://127.0.0.1:8000'
19access_key='0555b35654ad1656d804'
20secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
21
22client = 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
30topic_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
ec96510d
FG
47print(client.put_bucket_notification_configuration(Bucket=bucketname,
48 NotificationConfiguration={'TopicConfigurations': topic_conf_list}))