Create a bucket notification configuration using the ObjectScale APIs
Prerequisites
Before you can create bucket notification configuration, you must have:
Created an object store and a bucket within the object store.
Set up the WebHook destination configuration.
Steps
Create the
NotificationConfigurations file with your config xml.
When creating the bucket notification configuration(s), use the value from
$WEBHOOK_URN in the
<Topic></Topic> of the desired
TopicConfiguration .
ObjectScale provides event notifications for the following types of events.
Supported Event Type
Description
s3:ObjectCreated:Put
An object is created via an S3 PUT operation
s3:ObjectCreated:Copy
An object is created via an S3 COPY operation
s3:ObjectCreated:CompleteMultipartUpload
An object is created via an S3 CompleteMultipartUpload operation
s3:ObjectCreated:*
Any time an object is created
s3:ObjectRemoved:Deleted
Any time a non-versioned object is deleted or an object version is permanently deleted
s3:ObjectRemoved:DeleteMarkerCreated
Any time a delete marker is created for a versioned object
s3:ObjectRemoved:*
Any time an object is deleted
The example below shows a configuration which listens for all
ObjectCreated and
ObjectRemoved events.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<NotificationConfiguration xmlns = "http://s3.amazonaws.com/doc/2006-03-01/">
<TopicConfiguration>
<Id>MyConfiguration</Id>
<Event>s3:ObjectCreated:*</Event>
<Event>s3:ObjectRemoved:*</Event>
<Topic>urn:objectscale:webhook::722d25f2-9c5b-41fe-82ac-605782945488:MyWebhook</Topic>
</TopicConfiguration>
</NotificationConfiguration>
Put the notification configuration to the bucket
s3curl.pl --ord --debug --id=<ACCESS_KEY> --key=<SECRET> --calculateContentMd5 --put=<PATH_TO_CONFIG> -- http://$(kubectl get svc |awk '/-s3/{print $4}'):80/${BUCKET}?notification -v
Verify the bucket notification configuration was set in the bucket.
s3curl.pl --ord --debug --id=<ACCESS_KEY> --key=<SECRET> http://$(kubectl get svc |awk '/-s3/{print $4}'):80/{BUCKET}?notification -v | xmllint -format -
Results
You will now receive notification record output like this in your WebHook server as users perform S3 operations in the monitored bucket. For an example webhook server listening, see
Sample setting of simple listener at Webhook server .
Received notification #7 from ::ffff:172.17.0.38
{
"Records": [
{
"eventVersion": "2.2",
"eventSource": "aws:s3",
"awsRegion": "us-west-2",
"eventTime": "2021-02-12T02:14:48.398Z",
"eventName": "s3:ObjectCreated:Put",
"userIdentity": {
"principalId": "urn:ecs:iam::ad126a31-0286-4567-9670-c6032d1d89ac:root"
},
"requestParameters": {
"sourceIPAddress": "172.17.0.1"
},
"responseElements": {
"x-amz-request-id": "ac11001b:17793e42a6a:a7:147",
"x-amz-id-2": "87fec1b544f39058bab52f8dec0a0e257a3703454c40e260355f1578bc597406"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "MyConfiguration1",
"bucket": {
"name": "bucket01",
"ownerIdentity": {
"principalId": "urn:ecs:iam::ad126a31-0286-4567-9670-c6032d1d89ac:root"
},
"arn": ".bucket01"
},
"object": {
"key": "object-for-notification",
"size": "10",
"etag": "c239368c6b3ec9b9dbc5a6b799e3756a",
"versionId": "AAABd5QE804oTME0iiFB2rY0z1_bH-nEK7w",
"sequencer": "100000000000000000000000000000000000000000072e338"
}
}
}
]
}
Sample setting of simple listener at Webhook server
NOTE: Requires
npm and
nodejs installed:
mkdir webhook
cd webhook
npm init -y
npm install express body-parser
# create index.js from the linked file
node index.js
Webhook listening on :3000 /hook
Content of
index.js
const express = require("express")
const bodyParser = require("body-parser")
const app = express()
const PORT = 3000
const PATH = "/hook"
count = 0
app.use(bodyParser.json())
app.post(PATH, (req, res) => {
count++
console.log("Received notification #"
console.log(JSON.stringify(req.body, null, 2))
res.status(200).end()
})
app.listen(PORT, () => console.log(`Webhook listening on :${PORT} ${PATH}`))