在存儲桶級別創(chuàng)建存儲桶通知。這些需要 與發(fā)送存儲桶通知的目標(biāo)一起發(fā)布。桶 通知是 S3 操作。
先決條件
-
運(yùn)行 IBM Storage Ceph 集群,帶有 Ceph Object Gateway。
-
正在運(yùn)行的 HTTP 服務(wù)器、RabbitMQ 服務(wù)器或 Kafka 服務(wù)器。
-
根級訪問。
-
用戶訪問密鑰和私有密鑰。
-
終結(jié)點(diǎn)參數(shù)。
重要:IBM 支持事件,例如 、 、 和 。IBM 還支持事件,例如 和 。ObjectCreate
put
post
multipartUpload
copy
ObjectRemove
object_delete
s3_multi_object_delete
下面列出了創(chuàng)建存儲桶通知的兩種方法:
-
使用 boto 腳本
-
使用 AWS CLI
程序
使用 boto 腳本
-
安裝 python3-boto3 軟件包:
例
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm">[user@client ~]$ dnf install python3-boto3</code></span></span></span>
-
創(chuàng)建 S3 存儲桶。
-
創(chuàng)建一個(gè) python 腳本,為 、 或 協(xié)議創(chuàng)建 SNS 主題:
topic.py
http
amqp
kafka
例
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm">import boto3 from botocore.client import Config import sys # endpoint and keys from vstart endpoint = 'http://127.0.0.1:8000' access_key='0555b35654ad1656d804' secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' client = boto3.client('sns', endpoint_url=endpoint, aws_access_key_id=access_key, aws_secret_access_key=secret_key, config=Config(signature_version='s3')) attributes = {"push-endpoint": "amqp://localhost:5672", "amqp-exchange": "ex1", "amqp-ack-level": "broker"} client.create_topic(topic_name="mytopic", Attributes=attributes)</code></span></span></span>
-
Run the python script for creating topic:
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> python3 topic.py</code></span></span></span>
-
Create a python script?to create S3 bucket notification for?and?events:
notification.py
s3:objectCreate
s3:objectRemove
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm">import boto3 import sys # bucket name as first argument bucketname = sys.argv[1] # topic ARN as second argument topic_arn = sys.argv[2] # notification id as third argument notification_id = sys.argv[3] # endpoint and keys from vstart endpoint = 'http://127.0.0.1:8000' access_key='0555b35654ad1656d804' secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' client = boto3.client('s3', endpoint_url=endpoint, aws_access_key_id=access_key, aws_secret_access_key=secret_key) # regex filter on the object name and metadata based filtering are extension to AWS S3 API # bucket and topic should be created beforehand topic_conf_list = [{'Id': notification_id, 'TopicArn': topic_arn, 'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'], }] client.put_bucket_notification_configuration( Bucket=bucketname, NotificationConfiguration={ 'TopicConfigurations': [ { 'Id': notification_name, 'TopicArn': topic_arn, 'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'] }]})</code></span></span></span>
-
Run the python script for creating the bucket notification:
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> python3 notification.py</code></span></span></span>
-
Create S3 objects in the bucket.
-
Fetch the notification configuration:
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm">endpoint = 'http://127.0.0.1:8000' access_key='0555b35654ad1656d804' secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' client = boto3.client('s3', endpoint_url=endpoint, aws_access_key_id=access_key, aws_secret_access_key=secret_key) # getting a specific notification configuration is an extension to AWS S3 API print(client.get_bucket_notification_configuration(Bucket=bucketname))</code></span></span></span>
-
Optional: Delete the objects.
-
Verify the object deletion events at the?,?, or?receiver.
http
rabbitmq
kafka
-
Using the AWS CLI
-
Create topic:
Syntax文章來源:http://www.zghlxwxcb.cn/news/detail-553020.html
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> aws --endpoint=_AWS_END_POINT_ sns create-topic --name NAME --attributes=ATTRIBUTES_FILE</code></span></span></span>
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> [user@client ~]$ aws --endpoint=http://localhost sns create-topic --name test-kafka --attributes=file://topic.json sample topic.json: {"push-endpoint": "kafka://localhost","verify-ssl": "False", "kafka-ack-level": "broker", "persistent":"true"} ref: https://docs.aws.amazon.com/cli/latest/reference/sns/create-topic.html</code></span></span></span>
-
Create the bucket notification:
Syntax
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> aws s3api put-bucket-notification-configuration --bucket BUCKET_NAME --notification-configuration NOTIFICATION_FILE</code></span></span></span>
Example
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> [user@client ~]$ aws s3api put-bucket-notification-configuration --bucket my-bucket --notification-configuration file://notification.json sample notification.json { "TopicConfigurations": [ { "Id": "test_notification", "TopicArn": "arn:aws:sns:us-west-2:123456789012:test-kafka", "Events": [ "s3:ObjectCreated:*" ] } ] }</code></span></span></span>
-
Fetch the notification configuration:
Syntax
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> aws s3api --endpoint=_AWS_ENDPOINT_ get-bucket-notification-configuration --bucket BUCKET_NAME</code></span></span></span>
例文章來源地址http://www.zghlxwxcb.cn/news/detail-553020.html
<span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><span style="background-color:#1e1e1e"><code class="language-plaintext-ibm"> [user@client ~]$ aws s3api --endpoint=http://localhost get-bucket-notification-configuration --bucket my-bucket { "TopicConfigurations": [ { "Id": "test_notification", "TopicArn": "arn:aws:sns:default::test-kafka", "Events": [ "s3:ObjectCreated:*" ] } ] }</code></span></span></span>
到了這里,關(guān)于Ceph入門到精通-創(chuàng)建存儲桶通知的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!