Skip to content

Instantly share code, notes, and snippets.

@yuvalif
Last active July 29, 2022 20:24
Show Gist options
  • Select an option

  • Save yuvalif/d50bcc3d27121732ffbbafe7b7146112 to your computer and use it in GitHub Desktop.

Select an option

Save yuvalif/d50bcc3d27121732ffbbafe7b7146112 to your computer and use it in GitHub Desktop.

this is based on the following PR as a prerequisite, setup 2 zones multisite setup:

MON=1 OSD=1 MDS=0 MGR=0 ../src/test/rgw/test-rgw-multisite.sh 

to use the AWS CLI tool, following env variables should be set:

 export AWS_ACCESS_KEY_ID=1234567890
 export AWS_SECRET_ACCESS_KEY=pencil
 export AWS_DEFAULT_REGION=zg1

now, in a different terminal start an HTTP server (with POST handler):

wget https://gist.githubusercontent.com/mdonkers/63e115cc0c79b4f6b8b3a6b797e485c7/raw/a6a1d090ac8549dac8f2bd607bd64925de997d40/server.py
python server.py 10900

going back to the first terminal, create a topic on both zones (pointing to the above HTTP server)

aws --endpoint-url http://localhost:8001 sns create-topic --name=fishtopic --attributes='{"push-endpoint": "http://localhost:10900"}'
aws --endpoint-url http://localhost:8002 sns create-topic --name=fishtopic --attributes='{"push-endpoint": "http://localhost:10900"}'

now create the bucket:

aws --endpoint-url http://localhost:8001 s3 mb s3://mybucket

now create notifications (that should be triggered when objects are synced) on both zones:

aws --endpoint-url http://localhost:8001 s3api put-bucket-notification-configuration --bucket mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:zg1::fishtopic", "Events": ["s3:ObjectSynced:*"]}]}'
aws --endpoint-url http://localhost:8002 s3api put-bucket-notification-configuration --bucket mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:zg1::fishtopic", "Events": ["s3:ObjectSynced:*"]}]}'

just to make sure that things are working, you can create a regular notification:

aws --endpoint-url http://localhost:8001 s3api put-bucket-notification-configuration --bucket mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:zg1::fishtopic", "Events": []}]}'
aws --endpoint-url http://localhost:8002 s3api put-bucket-notification-configuration --bucket mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:zg1::fishtopic", "Events": []}]}'

now, create a file and upload it:

head -c 1M < /dev/urandom > myfile
aws --endpoint-url http://localhost:8001 s3 cp myfile s3://mybucket

the HTTP server, should show 2 notifications, one for the PUT event and one for the sync event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment