storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/docs/bucket/notifications/README.md (about) 1 # MinIO Bucket Notification Guide [](https://slack.min.io) 2 3 Events occurring on objects in a bucket can be monitored using bucket event notifications. 4 5 > NOTE: Gateway mode does not support bucket notifications (except NAS gateway). 6 7 Various event types supported by MinIO server are 8 9 | Supported Object Event Types | | | 10 | :---------------------- | ------------------------------------------ | ------------------------------------- | 11 | `s3:ObjectCreated:Put` | `s3:ObjectCreated:CompleteMultipartUpload` | `s3:ObjectAccessed:Head` | 12 | `s3:ObjectCreated:Post` | `s3:ObjectRemoved:Delete` | `s3:ObjectRemoved:DeleteMarkerCreated` | 13 | `s3:ObjectCreated:Copy` | `s3:ObjectAccessed:Get` | | 14 | `s3:ObjectCreated:PutRetention` | `s3:ObjectCreated:PutLegalHold` | | 15 | `s3:ObjectAccessed:GetRetention` | `s3:ObjectAccessed:GetLegalHold` | | 16 17 | Supported Replication Event Types | 18 | :------------ | 19 | `s3:Replication:OperationFailedReplication` | 20 | `s3:Replication:OperationCompletedReplication` | 21 | `s3:Replication:OperationNotTracked` | 22 | `s3:Replication:OperationMissedThreshold` | 23 | `s3:Replication:OperationReplicatedAfterThreshold` | 24 25 | Supported ILM Transition Event Types | 26 | :----- | 27 | `s3:ObjectRestore:Post` | 28 | `s3:ObjectRestore:Completed` | 29 30 | Supported Global Event Types (Only supported through ListenNotification API) | 31 | :----- | 32 | `s3:BucketCreated` | 33 | `s3:BucketRemoved` | 34 35 36 Use client tools like `mc` to set and listen for event notifications using the [`event` sub-command](https://docs.min.io/docs/minio-client-complete-guide#events). MinIO SDK's [`BucketNotification` APIs](https://docs.min.io/docs/golang-client-api-reference#SetBucketNotification) can also be used. The notification message MinIO sends to publish an event is a JSON message with the following [structure](https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html). 37 38 Bucket events can be published to the following targets: 39 40 | Supported Notification Targets | | | 41 | :-------------------------------- | --------------------------- | ------------------------------- | 42 | [`AMQP`](#AMQP) | [`Redis`](#Redis) | [`MySQL`](#MySQL) | 43 | [`MQTT`](#MQTT) | [`NATS`](#NATS) | [`Apache Kafka`](#apache-kafka) | 44 | [`Elasticsearch`](#Elasticsearch) | [`PostgreSQL`](#PostgreSQL) | [`Webhooks`](#webhooks) | 45 | [`NSQ`](#NSQ) | | | 46 47 ## Prerequisites 48 49 - Install and configure MinIO Server from [here](https://docs.min.io/docs/minio-quickstart-guide). 50 - Install and configure MinIO Client from [here](https://docs.min.io/docs/minio-client-quickstart-guide). 51 52 ``` 53 $ mc admin config get myminio | grep notify 54 notify_webhook publish bucket notifications to webhook endpoints 55 notify_amqp publish bucket notifications to AMQP endpoints 56 notify_kafka publish bucket notifications to Kafka endpoints 57 notify_mqtt publish bucket notifications to MQTT endpoints 58 notify_nats publish bucket notifications to NATS endpoints 59 notify_nsq publish bucket notifications to NSQ endpoints 60 notify_mysql publish bucket notifications to MySQL databases 61 notify_postgres publish bucket notifications to Postgres databases 62 notify_elasticsearch publish bucket notifications to Elasticsearch endpoints 63 notify_redis publish bucket notifications to Redis datastores 64 ``` 65 66 > NOTE: 67 > - '\*' at the end of arg means its mandatory. 68 > - '\*' at the end of the values, means its the default value for the arg. 69 > - When configured using environment variables, the `:name` can be specified using this format `MINIO_NOTIFY_WEBHOOK_ENABLE_<name>`. 70 71 <a name="AMQP"></a> 72 73 ## Publish MinIO events via AMQP 74 75 Install RabbitMQ from [here](https://www.rabbitmq.com/). 76 77 ### Step 1: Add AMQP endpoint to MinIO 78 79 The AMQP configuration is located under the sub-system `notify_amqp` top-level key. Create a configuration key-value pair here for your AMQP instance. The key is a name for your AMQP endpoint, and the value is a collection of key-value parameters described in the table below. 80 81 ``` 82 KEY: 83 notify_amqp[:name] publish bucket notifications to AMQP endpoints 84 85 ARGS: 86 url* (url) AMQP server endpoint e.g. `amqp://myuser:mypassword@localhost:5672` 87 exchange (string) name of the AMQP exchange 88 exchange_type (string) AMQP exchange type 89 routing_key (string) routing key for publishing 90 mandatory (on|off) quietly ignore undelivered messages when set to 'off', default is 'on' 91 durable (on|off) persist queue across broker restarts when set to 'on', default is 'off' 92 no_wait (on|off) non-blocking message delivery when set to 'on', default is 'off' 93 internal (on|off) set to 'on' for exchange to be not used directly by publishers, but only when bound to other exchanges 94 auto_deleted (on|off) auto delete queue when set to 'on', when there are no consumers 95 delivery_mode (number) set to '1' for non-persistent or '2' for persistent queue 96 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 97 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 98 comment (sentence) optionally add a comment to this setting 99 ``` 100 101 Or environment variables 102 103 ``` 104 KEY: 105 notify_amqp[:name] publish bucket notifications to AMQP endpoints 106 107 ARGS: 108 MINIO_NOTIFY_AMQP_ENABLE* (on|off) enable notify_amqp target, default is 'off' 109 MINIO_NOTIFY_AMQP_URL* (url) AMQP server endpoint e.g. `amqp://myuser:mypassword@localhost:5672` 110 MINIO_NOTIFY_AMQP_EXCHANGE (string) name of the AMQP exchange 111 MINIO_NOTIFY_AMQP_EXCHANGE_TYPE (string) AMQP exchange type 112 MINIO_NOTIFY_AMQP_ROUTING_KEY (string) routing key for publishing 113 MINIO_NOTIFY_AMQP_MANDATORY (on|off) quietly ignore undelivered messages when set to 'off', default is 'on' 114 MINIO_NOTIFY_AMQP_DURABLE (on|off) persist queue across broker restarts when set to 'on', default is 'off' 115 MINIO_NOTIFY_AMQP_NO_WAIT (on|off) non-blocking message delivery when set to 'on', default is 'off' 116 MINIO_NOTIFY_AMQP_INTERNAL (on|off) set to 'on' for exchange to be not used directly by publishers, but only when bound to other exchanges 117 MINIO_NOTIFY_AMQP_AUTO_DELETED (on|off) auto delete queue when set to 'on', when there are no consumers 118 MINIO_NOTIFY_AMQP_DELIVERY_MODE (number) set to '1' for non-persistent or '2' for persistent queue 119 MINIO_NOTIFY_AMQP_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 120 MINIO_NOTIFY_AMQP_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 121 MINIO_NOTIFY_AMQP_COMMENT (sentence) optionally add a comment to this setting 122 ``` 123 124 MinIO supports persistent event store. The persistent store will backup events when the AMQP broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 125 126 To update the configuration, use `mc admin config get notify_amqp` command to get the current configuration for `notify_amqp`. 127 128 ```sh 129 $ mc admin config get myminio/ notify_amqp 130 notify_amqp:1 delivery_mode="0" exchange_type="" no_wait="off" queue_dir="" queue_limit="0" url="" auto_deleted="off" durable="off" exchange="" internal="off" mandatory="off" routing_key="" 131 ``` 132 133 Use `mc admin config set` command to update the configuration for the deployment.Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:amqp` at start-up if there were no errors. 134 135 An example configuration for RabbitMQ is shown below: 136 137 ```sh 138 $ mc admin config set myminio/ notify_amqp:1 exchange="bucketevents" exchange_type="fanout" mandatory="false" no_wait="false" url="amqp://myuser:mypassword@localhost:5672" auto_deleted="false" delivery_mode="0" durable="false" internal="false" routing_key="bucketlogs" 139 ``` 140 141 MinIO supports all the exchanges available in [RabbitMQ](https://www.rabbitmq.com/). For this setup, we are using `fanout` exchange. 142 143 Note that, you can add as many AMQP server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the AMQP instance and an object of per-server configuration parameters. 144 145 ### Step 2: Enable bucket notification using MinIO client 146 147 We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:amqp`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation. 148 149 ``` 150 mc mb myminio/images 151 mc event add myminio/images arn:minio:sqs::1:amqp --suffix .jpg 152 mc event list myminio/images 153 arn:minio:sqs::1:amqp s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 154 ``` 155 156 ### Step 3: Test on RabbitMQ 157 158 The python program below waits on the queue exchange `bucketevents` and prints event notifications on the console. We use [Pika Python Client](https://www.rabbitmq.com/tutorials/tutorial-three-python.html) library to do this. 159 160 ```py 161 #!/usr/bin/env python 162 import pika 163 164 connection = pika.BlockingConnection(pika.ConnectionParameters( 165 host='localhost')) 166 channel = connection.channel() 167 168 channel.exchange_declare(exchange='bucketevents', 169 exchange_type='fanout') 170 171 result = channel.queue_declare(exclusive=False) 172 queue_name = result.method.queue 173 174 channel.queue_bind(exchange='bucketevents', 175 queue=queue_name) 176 177 print(' [*] Waiting for logs. To exit press CTRL+C') 178 179 def callback(ch, method, properties, body): 180 print(" [x] %r" % body) 181 182 channel.basic_consume(callback, 183 queue=queue_name, 184 no_ack=False) 185 186 channel.start_consuming() 187 ``` 188 189 Execute this example python program to watch for RabbitMQ events on the console. 190 191 ```py 192 python rabbit.py 193 ``` 194 195 Open another terminal and upload a JPEG image into `images` bucket. 196 197 ``` 198 mc cp myphoto.jpg myminio/images 199 ``` 200 201 You should receive the following event notification via RabbitMQ once the upload completes. 202 203 ```py 204 python rabbit.py 205 '{"Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"","eventTime":"2016–09–08T22:34:38.226Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"10.1.10.150:44576"},"responseElements":{},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":200436,"sequencer":"147279EAF9F40933"}}}],"level":"info","msg":"","time":"2016–09–08T15:34:38–07:00"}' 206 ``` 207 208 <a name="MQTT"></a> 209 210 ## Publish MinIO events MQTT 211 212 Install an MQTT Broker from [here](https://mosquitto.org/). 213 214 ### Step 1: Add MQTT endpoint to MinIO 215 216 The MQTT configuration is located as `notify_mqtt` key. Create a configuration key-value pair here for your MQTT instance. The key is a name for your MQTT endpoint, and the value is a collection of key-value parameters described in the table below. 217 218 ``` 219 KEY: 220 notify_mqtt[:name] publish bucket notifications to MQTT endpoints 221 222 ARGS: 223 broker* (uri) MQTT server endpoint e.g. `tcp://localhost:1883` 224 topic* (string) name of the MQTT topic to publish 225 username (string) MQTT username 226 password (string) MQTT password 227 qos (number) set the quality of service priority, defaults to '0' 228 keep_alive_interval (duration) keep-alive interval for MQTT connections in s,m,h,d 229 reconnect_interval (duration) reconnect interval for MQTT connections in s,m,h,d 230 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 231 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 232 comment (sentence) optionally add a comment to this setting 233 ``` 234 235 or environment variables 236 237 ``` 238 KEY: 239 notify_mqtt[:name] publish bucket notifications to MQTT endpoints 240 241 ARGS: 242 MINIO_NOTIFY_MQTT_ENABLE* (on|off) enable notify_mqtt target, default is 'off' 243 MINIO_NOTIFY_MQTT_BROKER* (uri) MQTT server endpoint e.g. `tcp://localhost:1883` 244 MINIO_NOTIFY_MQTT_TOPIC* (string) name of the MQTT topic to publish 245 MINIO_NOTIFY_MQTT_USERNAME (string) MQTT username 246 MINIO_NOTIFY_MQTT_PASSWORD (string) MQTT password 247 MINIO_NOTIFY_MQTT_QOS (number) set the quality of service priority, defaults to '0' 248 MINIO_NOTIFY_MQTT_KEEP_ALIVE_INTERVAL (duration) keep-alive interval for MQTT connections in s,m,h,d 249 MINIO_NOTIFY_MQTT_RECONNECT_INTERVAL (duration) reconnect interval for MQTT connections in s,m,h,d 250 MINIO_NOTIFY_MQTT_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 251 MINIO_NOTIFY_MQTT_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 252 MINIO_NOTIFY_MQTT_COMMENT (sentence) optionally add a comment to this setting 253 ``` 254 255 MinIO supports persistent event store. The persistent store will backup events when the MQTT broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 256 257 To update the configuration, use `mc admin config get` command to get the current configuration. 258 259 ```sh 260 $ mc admin config get myminio/ notify_mqtt 261 notify_mqtt:1 broker="" password="" queue_dir="" queue_limit="0" reconnect_interval="0s" keep_alive_interval="0s" qos="0" topic="" username="" 262 ``` 263 264 Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:mqtt` at start-up if there were no errors. 265 266 ```sh 267 $ mc admin config set myminio notify_mqtt:1 broker="tcp://localhost:1883" password="" queue_dir="" queue_limit="0" reconnect_interval="0s" keep_alive_interval="0s" qos="1" topic="minio" username="" 268 ``` 269 270 MinIO supports any MQTT server that supports MQTT 3.1 or 3.1.1 and can connect to them over TCP, TLS, or a Websocket connection using `tcp://`, `tls://`, or `ws://` respectively as the scheme for the broker url. See the [Go Client](http://www.eclipse.org/paho/clients/golang/) documentation for more information. 271 272 Note that, you can add as many MQTT server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the MQTT instance and an object of per-server configuration parameters. 273 274 ### Step 2: Enable bucket notification using MinIO client 275 276 We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:mqtt`. 277 278 ``` 279 mc mb myminio/images 280 mc event add myminio/images arn:minio:sqs::1:mqtt --suffix .jpg 281 mc event list myminio/images 282 arn:minio:sqs::1:amqp s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 283 ``` 284 285 ### Step 3: Test on MQTT 286 287 The python program below waits on mqtt topic `/minio` and prints event notifications on the console. We use [paho-mqtt](https://pypi.python.org/pypi/paho-mqtt/) library to do this. 288 289 ```py 290 #!/usr/bin/env python3 291 from __future__ import print_function 292 import paho.mqtt.client as mqtt 293 294 # This is the Subscriber 295 296 def on_connect(client, userdata, flags, rc): 297 print("Connected with result code "+str(rc)) 298 # qos level is set to 1 299 client.subscribe("minio", 1) 300 301 def on_message(client, userdata, msg): 302 print(msg.payload) 303 304 # client_id is a randomly generated unique ID for the mqtt broker to identify the connection. 305 client = mqtt.Client(client_id="myclientid",clean_session=False) 306 307 client.on_connect = on_connect 308 client.on_message = on_message 309 310 client.connect("localhost",1883,60) 311 client.loop_forever() 312 ``` 313 314 Execute this example python program to watch for MQTT events on the console. 315 316 ```py 317 python mqtt.py 318 ``` 319 320 Open another terminal and upload a JPEG image into `images` bucket. 321 322 ``` 323 mc cp myphoto.jpg myminio/images 324 ``` 325 326 You should receive the following event notification via MQTT once the upload completes. 327 328 ```py 329 python mqtt.py 330 {“Records”:[{“eventVersion”:”2.0",”eventSource”:”aws:s3",”awsRegion”:”",”eventTime”:”2016–09–08T22:34:38.226Z”,”eventName”:”s3:ObjectCreated:Put”,”userIdentity”:{“principalId”:”minio”},”requestParameters”:{“sourceIPAddress”:”10.1.10.150:44576"},”responseElements”:{},”s3":{“s3SchemaVersion”:”1.0",”configurationId”:”Config”,”bucket”:{“name”:”images”,”ownerIdentity”:{“principalId”:”minio”},”arn”:”arn:aws:s3:::images”},”object”:{“key”:”myphoto.jpg”,”size”:200436,”sequencer”:”147279EAF9F40933"}}}],”level”:”info”,”msg”:””,”time”:”2016–09–08T15:34:38–07:00"} 331 ``` 332 333 <a name="Elasticsearch"></a> 334 335 ## Publish MinIO events via Elasticsearch 336 337 Install [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) server. 338 339 This notification target supports two formats: _namespace_ and _access_. 340 341 When the _namespace_ format is used, MinIO synchronizes objects in the bucket with documents in the index. For each event in the MinIO, the server creates a document with the bucket and object name from the event as the document ID. Other details of the event are stored in the body of the document. Thus if an existing object is over-written in MinIO, the corresponding document in the Elasticsearch index is updated. If an object is deleted, the corresponding document is deleted from the index. 342 343 When the _access_ format is used, MinIO appends events as documents in an Elasticsearch index. For each event, a document with the event details, with the timestamp of document set to the event's timestamp is appended to an index. The ID of the documented is randomly generated by Elasticsearch. No documents are deleted or modified in this format. 344 345 The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity. 346 347 ### Step 1: Ensure minimum requirements are met 348 349 MinIO requires a 5.x series version of Elasticsearch. This is the latest major release series. Elasticsearch provides version upgrade migration guidelines [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html). 350 351 ### Step 2: Add Elasticsearch endpoint to MinIO 352 353 The Elasticsearch configuration is located in the `notify_elasticsearch` key. Create a configuration key-value pair here for your Elasticsearch instance. The key is a name for your Elasticsearch endpoint, and the value is a collection of key-value parameters described in the table below. 354 355 ``` 356 KEY: 357 notify_elasticsearch[:name] publish bucket notifications to Elasticsearch endpoints 358 359 ARGS: 360 url* (url) Elasticsearch server's address, with optional authentication info 361 index* (string) Elasticsearch index to store/update events, index is auto-created 362 format* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 363 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 364 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 365 username (string) username for Elasticsearch basic-auth 366 password (string) password for Elasticsearch basic-auth 367 comment (sentence) optionally add a comment to this setting 368 ``` 369 370 or environment variables 371 372 ``` 373 KEY: 374 notify_elasticsearch[:name] publish bucket notifications to Elasticsearch endpoints 375 376 ARGS: 377 MINIO_NOTIFY_ELASTICSEARCH_ENABLE* (on|off) enable notify_elasticsearch target, default is 'off' 378 MINIO_NOTIFY_ELASTICSEARCH_URL* (url) Elasticsearch server's address, with optional authentication info 379 MINIO_NOTIFY_ELASTICSEARCH_INDEX* (string) Elasticsearch index to store/update events, index is auto-created 380 MINIO_NOTIFY_ELASTICSEARCH_FORMAT* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 381 MINIO_NOTIFY_ELASTICSEARCH_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 382 MINIO_NOTIFY_ELASTICSEARCH_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 383 MINIO_NOTIFY_ELASTICSEARCH_USERNAME (string) username for Elasticsearch basic-auth 384 MINIO_NOTIFY_ELASTICSEARCH_PASSWORD (string) password for Elasticsearch basic-auth 385 MINIO_NOTIFY_ELASTICSEARCH_COMMENT (sentence) optionally add a comment to this setting 386 ``` 387 388 For example: `http://localhost:9200` or with authentication info `http://elastic:MagicWord@127.0.0.1:9200`. 389 390 MinIO supports persistent event store. The persistent store will backup events when the Elasticsearch broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 391 392 If Elasticsearch has authentication enabled, the credentials can be supplied to MinIO via the `url` parameter formatted as `PROTO://USERNAME:PASSWORD@ELASTICSEARCH_HOST:PORT`. 393 394 To update the configuration, use `mc admin config get` command to get the current configuration. 395 396 ```sh 397 $ mc admin config get myminio/ notify_elasticsearch 398 notify_elasticsearch:1 queue_limit="0" url="" format="namespace" index="" queue_dir="" 399 ``` 400 401 Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:elasticsearch` at start-up if there were no errors. 402 403 ```sh 404 $ mc admin config set myminio notify_elasticsearch:1 queue_limit="0" url="http://127.0.0.1:9200" format="namespace" index="minio_events" queue_dir="" username="" password="" 405 ``` 406 407 Note that, you can add as many Elasticsearch server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the Elasticsearch instance and an object of per-server configuration parameters. 408 409 ### Step 3: Enable bucket notification using MinIO client 410 411 We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new document is added or an existing document is updated in the Elasticsearch index configured above. When an existing object is deleted, the corresponding document is deleted from the index. Thus, the rows in the Elasticsearch index, reflect the `.jpg` objects in the `images` bucket. 412 413 To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). 414 415 With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following: 416 417 ``` 418 mc mb myminio/images 419 mc event add myminio/images arn:minio:sqs::1:elasticsearch --suffix .jpg 420 mc event list myminio/images 421 arn:minio:sqs::1:elasticsearch s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 422 ``` 423 424 ### Step 4: Test on Elasticsearch 425 426 Upload a JPEG image into `images` bucket. 427 428 ``` 429 mc cp myphoto.jpg myminio/images 430 ``` 431 432 Use curl to view contents of `minio_events` index. 433 434 ``` 435 $ curl "http://localhost:9200/minio_events/_search?pretty=true" 436 { 437 "took" : 40, 438 "timed_out" : false, 439 "_shards" : { 440 "total" : 5, 441 "successful" : 5, 442 "failed" : 0 443 }, 444 "hits" : { 445 "total" : 1, 446 "max_score" : 1.0, 447 "hits" : [ 448 { 449 "_index" : "minio_events", 450 "_type" : "event", 451 "_id" : "images/myphoto.jpg", 452 "_score" : 1.0, 453 "_source" : { 454 "Records" : [ 455 { 456 "eventVersion" : "2.0", 457 "eventSource" : "minio:s3", 458 "awsRegion" : "", 459 "eventTime" : "2017-03-30T08:00:41Z", 460 "eventName" : "s3:ObjectCreated:Put", 461 "userIdentity" : { 462 "principalId" : "minio" 463 }, 464 "requestParameters" : { 465 "sourceIPAddress" : "127.0.0.1:38062" 466 }, 467 "responseElements" : { 468 "x-amz-request-id" : "14B09A09703FC47B", 469 "x-minio-origin-endpoint" : "http://192.168.86.115:9000" 470 }, 471 "s3" : { 472 "s3SchemaVersion" : "1.0", 473 "configurationId" : "Config", 474 "bucket" : { 475 "name" : "images", 476 "ownerIdentity" : { 477 "principalId" : "minio" 478 }, 479 "arn" : "arn:aws:s3:::images" 480 }, 481 "object" : { 482 "key" : "myphoto.jpg", 483 "size" : 6474, 484 "eTag" : "a3410f4f8788b510d6f19c5067e60a90", 485 "sequencer" : "14B09A09703FC47B" 486 } 487 }, 488 "source" : { 489 "host" : "127.0.0.1", 490 "port" : "38062", 491 "userAgent" : "MinIO (linux; amd64) minio-go/2.0.3 mc/2017-02-15T17:57:25Z" 492 } 493 } 494 ] 495 } 496 } 497 ] 498 } 499 } 500 ``` 501 502 This output shows that a document has been created for the event in Elasticsearch. 503 504 Here we see that the document ID is the bucket and object name. In case `access` format was used, the document ID would be automatically generated by Elasticsearch. 505 506 <a name="Redis"></a> 507 508 ## Publish MinIO events via Redis 509 510 Install [Redis](http://redis.io/download) server. For illustrative purposes, we have set the database password as "yoursecret". 511 512 This notification target supports two formats: _namespace_ and _access_. 513 514 When the _namespace_ format is used, MinIO synchronizes objects in the bucket with entries in a hash. For each entry, the key is formatted as "bucketName/objectName" for an object that exists in the bucket, and the value is the JSON-encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding entry in the hash is also updated or deleted. 515 516 When the _access_ format is used, MinIO appends events to a list using [RPUSH](https://redis.io/commands/rpush). Each item in the list is a JSON encoded list with two items, where the first item is a timestamp string, and the second item is a JSON object containing event data about the operation that happened in the bucket. No entries appended to the list are updated or deleted by MinIO in this format. 517 518 The steps below show how to use this notification target in `namespace` and `access` format. 519 520 ### Step 1: Add Redis endpoint to MinIO 521 522 The MinIO server configuration file is stored on the backend in json format.The Redis configuration is located in the `redis` key under the `notify` top-level key. Create a configuration key-value pair here for your Redis instance. The key is a name for your Redis endpoint, and the value is a collection of key-value parameters described in the table below. 523 524 ``` 525 KEY: 526 notify_redis[:name] publish bucket notifications to Redis datastores 527 528 ARGS: 529 address* (address) Redis server's address. For example: `localhost:6379` 530 key* (string) Redis key to store/update events, key is auto-created 531 format* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 532 password (string) Redis server password 533 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 534 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 535 comment (sentence) optionally add a comment to this setting 536 ``` 537 538 or environment variables 539 540 ``` 541 KEY: 542 notify_redis[:name] publish bucket notifications to Redis datastores 543 544 ARGS: 545 MINIO_NOTIFY_REDIS_ENABLE* (on|off) enable notify_redis target, default is 'off' 546 MINIO_NOTIFY_REDIS_KEY* (string) Redis key to store/update events, key is auto-created 547 MINIO_NOTIFY_REDIS_FORMAT* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 548 MINIO_NOTIFY_REDIS_PASSWORD (string) Redis server password 549 MINIO_NOTIFY_REDIS_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 550 MINIO_NOTIFY_REDIS_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 551 MINIO_NOTIFY_REDIS_COMMENT (sentence) optionally add a comment to this setting 552 ``` 553 554 MinIO supports persistent event store. The persistent store will backup events when the Redis broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 555 556 To update the configuration, use `mc admin config get` command to get the current configuration. 557 558 ```sh 559 $ mc admin config get myminio/ notify_redis 560 notify_redis:1 address="" format="namespace" key="" password="" queue_dir="" queue_limit="0" 561 ``` 562 563 Use `mc admin config set` command to update the configuration for the deployment.Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:redis` at start-up if there were no errors. 564 565 ```sh 566 $ mc admin config set myminio/ notify_redis:1 address="127.0.0.1:6379" format="namespace" key="bucketevents" password="yoursecret" queue_dir="" queue_limit="0" 567 ``` 568 569 Note that, you can add as many Redis server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the Redis instance and an object of per-server configuration parameters. 570 571 ### Step 2: Enable bucket notification using MinIO client 572 573 We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new key is added or an existing key is updated in the Redis hash configured above. When an existing object is deleted, the corresponding key is deleted from the Redis hash. Thus, the rows in the Redis hash, reflect the `.jpg` objects in the `images` bucket. 574 575 To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). 576 577 With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following: 578 579 ``` 580 mc mb myminio/images 581 mc event add myminio/images arn:minio:sqs::1:redis --suffix .jpg 582 mc event list myminio/images 583 arn:minio:sqs::1:redis s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 584 ``` 585 586 ### Step 3: Test on Redis 587 588 Start the `redis-cli` Redis client program to inspect the contents in Redis. Run the `monitor` Redis command. This prints each operation performed on Redis as it occurs. 589 590 ``` 591 redis-cli -a yoursecret 592 127.0.0.1:6379> monitor 593 OK 594 ``` 595 596 Open another terminal and upload a JPEG image into `images` bucket. 597 598 ``` 599 mc cp myphoto.jpg myminio/images 600 ``` 601 602 In the previous terminal, you will now see the operation that MinIO performs on Redis: 603 604 ``` 605 127.0.0.1:6379> monitor 606 OK 607 1490686879.650649 [0 172.17.0.1:44710] "PING" 608 1490686879.651061 [0 172.17.0.1:44710] "HSET" "minio_events" "images/myphoto.jpg" "{\"Records\":[{\"eventVersion\":\"2.0\",\"eventSource\":\"minio:s3\",\"awsRegion\":\"\",\"eventTime\":\"2017-03-28T07:41:19Z\",\"eventName\":\"s3:ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"minio\"},\"requestParameters\":{\"sourceIPAddress\":\"127.0.0.1:52234\"},\"responseElements\":{\"x-amz-request-id\":\"14AFFBD1ACE5F632\",\"x-minio-origin-endpoint\":\"http://192.168.86.115:9000\"},\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"Config\",\"bucket\":{\"name\":\"images\",\"ownerIdentity\":{\"principalId\":\"minio\"},\"arn\":\"arn:aws:s3:::images\"},\"object\":{\"key\":\"myphoto.jpg\",\"size\":2586,\"eTag\":\"5d284463f9da279f060f0ea4d11af098\",\"sequencer\":\"14AFFBD1ACE5F632\"}},\"source\":{\"host\":\"127.0.0.1\",\"port\":\"52234\",\"userAgent\":\"MinIO (linux; amd64) minio-go/2.0.3 mc/2017-02-15T17:57:25Z\"}}]}" 609 ``` 610 611 Here we see that MinIO performed `HSET` on `minio_events` key. 612 613 In case, `access` format was used, then `minio_events` would be a list, and the MinIO server would have performed an `RPUSH` to append to the list. A consumer of this list would ideally use `BLPOP` to remove list items from the left-end of the list. 614 615 <a name="NATS"></a> 616 617 ## Publish MinIO events via NATS 618 619 Install NATS from [here](http://nats.io/). 620 621 ### Step 1: Add NATS endpoint to MinIO 622 623 MinIO supports persistent event store. The persistent store will backup events when the NATS broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 624 625 ``` 626 KEY: 627 notify_nats[:name] publish bucket notifications to NATS endpoints 628 629 ARGS: 630 address* (address) NATS server address e.g. '0.0.0.0:4222' 631 subject* (string) NATS subscription subject 632 username (string) NATS username 633 password (string) NATS password 634 token (string) NATS token 635 tls (on|off) set to 'on' to enable TLS 636 tls_skip_verify (on|off) trust server TLS without verification, defaults to "on" (verify) 637 ping_interval (duration) client ping commands interval in s,m,h,d. Disabled by default 638 streaming (on|off) set to 'on', to use streaming NATS server 639 streaming_async (on|off) set to 'on', to enable asynchronous publish 640 streaming_max_pub_acks_in_flight (number) number of messages to publish without waiting for ACKs 641 streaming_cluster_id (string) unique ID for NATS streaming cluster 642 cert_authority (string) path to certificate chain of the target NATS server 643 client_cert (string) client cert for NATS mTLS auth 644 client_key (string) client cert key for NATS mTLS auth 645 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 646 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 647 comment (sentence) optionally add a comment to this setting 648 ``` 649 650 or environment variables 651 ``` 652 KEY: 653 notify_nats[:name] publish bucket notifications to NATS endpoints 654 655 ARGS: 656 MINIO_NOTIFY_NATS_ENABLE* (on|off) enable notify_nats target, default is 'off' 657 MINIO_NOTIFY_NATS_ADDRESS* (address) NATS server address e.g. '0.0.0.0:4222' 658 MINIO_NOTIFY_NATS_SUBJECT* (string) NATS subscription subject 659 MINIO_NOTIFY_NATS_USERNAME (string) NATS username 660 MINIO_NOTIFY_NATS_PASSWORD (string) NATS password 661 MINIO_NOTIFY_NATS_TOKEN (string) NATS token 662 MINIO_NOTIFY_NATS_TLS (on|off) set to 'on' to enable TLS 663 MINIO_NOTIFY_NATS_TLS_SKIP_VERIFY (on|off) trust server TLS without verification, defaults to "on" (verify) 664 MINIO_NOTIFY_NATS_PING_INTERVAL (duration) client ping commands interval in s,m,h,d. Disabled by default 665 MINIO_NOTIFY_NATS_STREAMING (on|off) set to 'on', to use streaming NATS server 666 MINIO_NOTIFY_NATS_STREAMING_ASYNC (on|off) set to 'on', to enable asynchronous publish 667 MINIO_NOTIFY_NATS_STREAMING_MAX_PUB_ACKS_IN_FLIGHT (number) number of messages to publish without waiting for ACKs 668 MINIO_NOTIFY_NATS_STREAMING_CLUSTER_ID (string) unique ID for NATS streaming cluster 669 MINIO_NOTIFY_NATS_CERT_AUTHORITY (string) path to certificate chain of the target NATS server 670 MINIO_NOTIFY_NATS_CLIENT_CERT (string) client cert for NATS mTLS auth 671 MINIO_NOTIFY_NATS_CLIENT_KEY (string) client cert key for NATS mTLS auth 672 MINIO_NOTIFY_NATS_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 673 MINIO_NOTIFY_NATS_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 674 MINIO_NOTIFY_NATS_COMMENT (sentence) optionally add a comment to this setting 675 ``` 676 677 To update the configuration, use `mc admin config get` command to get the current configuration file for the minio deployment. 678 679 ```sh 680 $ mc admin config get myminio/ notify_nats 681 notify_nats:1 password="yoursecret" streaming_max_pub_acks_in_flight="10" subject="" address="0.0.0.0:4222" token="" username="yourusername" ping_interval="0" queue_limit="0" tls="off" tls_skip_verify="off" streaming_async="on" queue_dir="" streaming_cluster_id="test-cluster" streaming_enable="on" 682 ``` 683 684 Use `mc admin config set` command to update the configuration for the deployment.Restart MinIO server to reflect config changes. `bucketevents` is the subject used by NATS in this example. 685 686 ```sh 687 $ mc admin config set myminio notify_nats:1 password="yoursecret" streaming_max_pub_acks_in_flight="10" subject="" address="0.0.0.0:4222" token="" username="yourusername" ping_interval="0" queue_limit="0" tls="off" streaming_async="on" queue_dir="" streaming_cluster_id="test-cluster" streaming_enable="on" 688 ``` 689 690 MinIO server also supports [NATS Streaming mode](http://nats.io/documentation/streaming/nats-streaming-intro/) that offers additional functionality like `At-least-once-delivery`, and `Publisher rate limiting`. To configure MinIO server to send notifications to NATS Streaming server, update the MinIO server configuration file as follows: 691 692 Read more about sections `cluster_id`, `client_id` on [NATS documentation](https://github.com/nats-io/nats-streaming-server/blob/master/README.md). Section `maxPubAcksInflight` is explained [here](https://github.com/nats-io/stan.go#publisher-rate-limiting). 693 694 ### Step 2: Enable bucket notification using MinIO client 695 696 We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted from `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:nats`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation. 697 698 ``` 699 mc mb myminio/images 700 mc event add myminio/images arn:minio:sqs::1:nats --suffix .jpg 701 mc event list myminio/images 702 arn:minio:sqs::1:nats s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 703 ``` 704 705 ### Step 3: Test on NATS 706 707 If you use NATS server, check out this sample program below to log the bucket notification added to NATS. 708 709 ```go 710 package main 711 712 // Import Go and NATS packages 713 import ( 714 "log" 715 "runtime" 716 717 "github.com/nats-io/nats.go" 718 ) 719 720 func main() { 721 722 // Create server connection 723 natsConnection, _ := nats.Connect("nats://yourusername:yoursecret@localhost:4222") 724 log.Println("Connected") 725 726 // Subscribe to subject 727 log.Printf("Subscribing to subject 'bucketevents'\n") 728 natsConnection.Subscribe("bucketevents", func(msg *nats.Msg) { 729 730 // Handle the message 731 log.Printf("Received message '%s\n", string(msg.Data)+"'") 732 }) 733 734 // Keep the connection alive 735 runtime.Goexit() 736 } 737 ``` 738 739 ``` 740 go run nats.go 741 2016/10/12 06:39:18 Connected 742 2016/10/12 06:39:18 Subscribing to subject 'bucketevents' 743 ``` 744 745 Open another terminal and upload a JPEG image into `images` bucket. 746 747 ``` 748 mc cp myphoto.jpg myminio/images 749 ``` 750 751 The example `nats.go` program prints event notification to console. 752 753 ``` 754 go run nats.go 755 2016/10/12 06:51:26 Connected 756 2016/10/12 06:51:26 Subscribing to subject 'bucketevents' 757 2016/10/12 06:51:33 Received message '{"EventType":"s3:ObjectCreated:Put","Key":"images/myphoto.jpg","Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"","eventTime":"2016-10-12T13:51:33Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"[::1]:57106"},"responseElements":{},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":56060,"eTag":"1d97bf45ecb37f7a7b699418070df08f","sequencer":"147CCD1AE054BFD0"}}}],"level":"info","msg":"","time":"2016-10-12T06:51:33-07:00"} 758 ``` 759 760 If you use NATS Streaming server, check out this sample program below to log the bucket notification added to NATS. 761 762 ```go 763 package main 764 765 // Import Go and NATS packages 766 import ( 767 "fmt" 768 "runtime" 769 770 "github.com/nats-io/stan.go" 771 ) 772 773 func main() { 774 775 var stanConnection stan.Conn 776 777 subscribe := func() { 778 fmt.Printf("Subscribing to subject 'bucketevents'\n") 779 stanConnection.Subscribe("bucketevents", func(m *stan.Msg) { 780 781 // Handle the message 782 fmt.Printf("Received a message: %s\n", string(m.Data)) 783 }) 784 } 785 786 787 stanConnection, _ = stan.Connect("test-cluster", "test-client", stan.NatsURL("nats://yourusername:yoursecret@0.0.0.0:4222"), stan.SetConnectionLostHandler(func(c stan.Conn, _ error) { 788 go func() { 789 for { 790 // Reconnect if the connection is lost. 791 if stanConnection == nil || stanConnection.NatsConn() == nil || !stanConnection.NatsConn().IsConnected() { 792 stanConnection, _ = stan.Connect("test-cluster", "test-client", stan.NatsURL("nats://yourusername:yoursecret@0.0.0.0:4222"), stan.SetConnectionLostHandler(func(c stan.Conn, _ error) { 793 if c.NatsConn() != nil { 794 c.NatsConn().Close() 795 } 796 _ = c.Close() 797 })) 798 if stanConnection != nil { 799 subscribe() 800 } 801 802 } 803 } 804 805 }() 806 })) 807 808 // Subscribe to subject 809 subscribe() 810 811 // Keep the connection alive 812 runtime.Goexit() 813 } 814 815 ``` 816 817 ``` 818 go run nats.go 819 2017/07/07 11:47:40 Connected 820 2017/07/07 11:47:40 Subscribing to subject 'bucketevents' 821 ``` 822 823 Open another terminal and upload a JPEG image into `images` bucket. 824 825 ``` 826 mc cp myphoto.jpg myminio/images 827 ``` 828 829 The example `nats.go` program prints event notification to console. 830 831 ``` 832 Received a message: {"EventType":"s3:ObjectCreated:Put","Key":"images/myphoto.jpg","Records":[{"eventVersion":"2.0","eventSource":"minio:s3","awsRegion":"","eventTime":"2017-07-07T18:46:37Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"minio"},"requestParameters":{"sourceIPAddress":"192.168.1.80:55328"},"responseElements":{"x-amz-request-id":"14CF20BD1EFD5B93","x-minio-origin-endpoint":"http://127.0.0.1:9000"},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"minio"},"arn":"arn:aws:s3:::images"},"object":{"key":"myphoto.jpg","size":248682,"eTag":"f1671feacb8bbf7b0397c6e9364e8c92","contentType":"image/jpeg","userDefined":{"content-type":"image/jpeg"},"versionId":"1","sequencer":"14CF20BD1EFD5B93"}},"source":{"host":"192.168.1.80","port":"55328","userAgent":"MinIO (linux; amd64) minio-go/2.0.4 mc/DEVELOPMENT.GOGET"}}],"level":"info","msg":"","time":"2017-07-07T11:46:37-07:00"} 833 ``` 834 835 <a name="PostgreSQL"></a> 836 837 ## Publish MinIO events via PostgreSQL 838 839 > NOTE: Until release RELEASE.2020-04-10T03-34-42Z PostgreSQL notification used to support following options: 840 > 841 > ``` 842 > host (hostname) Postgres server hostname (used only if `connection_string` is empty) 843 > port (port) Postgres server port, defaults to `5432` (used only if `connection_string` is empty) 844 > username (string) database username (used only if `connection_string` is empty) 845 > password (string) database password (used only if `connection_string` is empty) 846 > database (string) database name (used only if `connection_string` is empty) 847 > ``` 848 > 849 > These are now deprecated, if you plan to upgrade to any releases after *RELEASE.2020-04-10T03-34-42Z* make sure 850 > to migrate to only using *connection_string* option. To migrate, once you have upgraded all the servers use the 851 > following command to update the existing notification targets. 852 > 853 > ``` 854 > mc admin config set myminio/ notify_postgres[:name] connection_string="host=hostname port=2832 username=psqluser password=psqlpass database=bucketevents" 855 > ``` 856 > 857 > Please make sure this step is carried out, without this step PostgreSQL notification targets will not work, 858 > an error message will be shown on the console upon server upgrade/restart, make sure to follow the above 859 > instructions appropriately. For further questions please join our https://slack.min.io 860 861 Install [PostgreSQL](https://www.postgresql.org/) database server. For illustrative purposes, we have set the "postgres" user password as `password` and created a database called `minio_events` to store the events. 862 863 This notification target supports two formats: _namespace_ and _access_. 864 865 When the _namespace_ format is used, MinIO synchronizes objects in the bucket with rows in the table. It creates rows with two columns: key and value. The key is the bucket and object name of an object that exists in MinIO. The value is JSON encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding row from this table is updated or deleted respectively. 866 867 When the _access_ format is used, MinIO appends events to a table. It creates rows with two columns: event_time and event_data. The event_time is the time at which the event occurred in the MinIO server. The event_data is the JSON encoded event data about the operation on an object. No rows are deleted or modified in this format. 868 869 The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity. 870 871 ### Step 1: Ensure minimum requirements are met 872 873 MinIO requires PostgreSQL version 9.5 or above. MinIO uses the [`INSERT ON CONFLICT`](https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT) (aka UPSERT) feature, introduced in version 9.5 and the [JSONB](https://www.postgresql.org/docs/9.4/static/datatype-json.html) data-type introduced in version 9.4. 874 875 ### Step 2: Add PostgreSQL endpoint to MinIO 876 877 The PostgreSQL configuration is located in the `notify_postgresql` key. Create a configuration key-value pair here for your PostgreSQL instance. The key is a name for your PostgreSQL endpoint, and the value is a collection of key-value parameters described in the table below. 878 879 ``` 880 KEY: 881 notify_postgres[:name] publish bucket notifications to Postgres databases 882 883 ARGS: 884 connection_string* (string) Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable" 885 table* (string) DB table name to store/update events, table is auto-created 886 format* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 887 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 888 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 889 max_open_connections (number) maximum number of open connections to the database, defaults to '2' 890 comment (sentence) optionally add a comment to this setting 891 ``` 892 893 or environment variables 894 ``` 895 KEY: 896 notify_postgres[:name] publish bucket notifications to Postgres databases 897 898 ARGS: 899 MINIO_NOTIFY_POSTGRES_ENABLE* (on|off) enable notify_postgres target, default is 'off' 900 MINIO_NOTIFY_POSTGRES_CONNECTION_STRING* (string) Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable" 901 MINIO_NOTIFY_POSTGRES_TABLE* (string) DB table name to store/update events, table is auto-created 902 MINIO_NOTIFY_POSTGRES_FORMAT* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 903 MINIO_NOTIFY_POSTGRES_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 904 MINIO_NOTIFY_POSTGRES_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 905 MINIO_NOTIFY_POSTGRES_COMMENT (sentence) optionally add a comment to this setting 906 MINIO_NOTIFY_POSTGRES_MAX_OPEN_CONNECTIONS (number) maximum number of open connections to the database, defaults to '2' 907 ``` 908 909 > NOTE: If the `max_open_connections` key or the environment variable `MINIO_NOTIFY_POSTGRES_MAX_OPEN_CONNECTIONS` is set to `0`, There will be no limit set on the number of 910 > open connections to the database. This setting is generally NOT recommended as the behavior may be inconsistent during recursive deletes in `namespace` format. 911 912 MinIO supports persistent event store. The persistent store will backup events when the PostgreSQL connection goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 913 914 Note that for illustration here, we have disabled SSL. In the interest of security, for production this is not recommended. 915 To update the configuration, use `mc admin config get` command to get the current configuration. 916 917 ```sh 918 $ mc admin config get myminio notify_postgres 919 notify_postgres:1 queue_dir="" connection_string="" queue_limit="0" table="" format="namespace" 920 ``` 921 922 Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:postgresql` at start-up if there were no errors. 923 924 ```sh 925 $ mc admin config set myminio notify_postgres:1 connection_string="host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable" table="bucketevents" format="namespace" 926 ``` 927 928 Note that, you can add as many PostgreSQL server endpoint configurations as needed by providing an identifier (like "1" in the example above) for the PostgreSQL instance and an object of per-server configuration parameters. 929 930 ### Step 3: Enable bucket notification using MinIO client 931 932 We will now enable bucket event notifications on a bucket named `images`. Whenever a JPEG image is created/overwritten, a new row is added or an existing row is updated in the PostgreSQL configured above. When an existing object is deleted, the corresponding row is deleted from the PostgreSQL table. Thus, the rows in the PostgreSQL table, reflect the `.jpg` objects in the `images` bucket. 933 934 To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). 935 936 With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following: 937 938 ``` 939 # Create bucket named `images` in myminio 940 mc mb myminio/images 941 # Add notification configuration on the `images` bucket using the MySQL ARN. The --suffix argument filters events. 942 mc event add myminio/images arn:minio:sqs::1:postgresql --suffix .jpg 943 # Print out the notification configuration on the `images` bucket. 944 mc event list myminio/images 945 mc event list myminio/images 946 arn:minio:sqs::1:postgresql s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 947 ``` 948 949 ### Step 4: Test on PostgreSQL 950 951 Open another terminal and upload a JPEG image into `images` bucket. 952 953 ``` 954 mc cp myphoto.jpg myminio/images 955 ``` 956 957 Open PostgreSQL terminal to list the rows in the `bucketevents` table. 958 959 ``` 960 $ psql -h 127.0.0.1 -U postgres -d minio_events 961 minio_events=# select * from bucketevents; 962 963 key | value 964 --------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 965 images/myphoto.jpg | {"Records": [{"s3": {"bucket": {"arn": "arn:aws:s3:::images", "name": "images", "ownerIdentity": {"principalId": "minio"}}, "object": {"key": "myphoto.jpg", "eTag": "1d97bf45ecb37f7a7b699418070df08f", "size": 56060, "sequencer": "147CE57C70B31931"}, "configurationId": "Config", "s3SchemaVersion": "1.0"}, "awsRegion": "", "eventName": "s3:ObjectCreated:Put", "eventTime": "2016-10-12T21:18:20Z", "eventSource": "aws:s3", "eventVersion": "2.0", "userIdentity": {"principalId": "minio"}, "responseElements": {}, "requestParameters": {"sourceIPAddress": "[::1]:39706"}}]} 966 (1 row) 967 ``` 968 969 <a name="MySQL"></a> 970 971 ## Publish MinIO events via MySQL 972 973 > NOTE: Until release RELEASE.2020-04-10T03-34-42Z MySQL notification used to support following options: 974 > 975 > ``` 976 > host (hostname) MySQL server hostname (used only if `dsn_string` is empty) 977 > port (port) MySQL server port (used only if `dsn_string` is empty) 978 > username (string) database username (used only if `dsn_string` is empty) 979 > password (string) database password (used only if `dsn_string` is empty) 980 > database (string) database name (used only if `dsn_string` is empty) 981 > ``` 982 > 983 > These are now deprecated, if you plan to upgrade to any releases after *RELEASE.2020-04-10T03-34-42Z* make sure 984 > to migrate to only using *dsn_string* option. To migrate, once you have upgraded all the servers use the 985 > following command to update the existing notification targets. 986 > 987 > ``` 988 > mc admin config set myminio/ notify_mysql[:name] dsn_string="mysqluser:mysqlpass@tcp(localhost:2832)/bucketevents" 989 > ``` 990 > 991 > Please make sure this step is carried out, without this step MySQL notification targets will not work, 992 > an error message will be shown on the console upon server upgrade/restart, make sure to follow the above 993 > instructions appropriately. For further questions please join our https://slack.min.io 994 995 Install MySQL from [here](https://dev.mysql.com/downloads/mysql/). For illustrative purposes, we have set the root password as `password` and created a database called `miniodb` to store the events. 996 997 This notification target supports two formats: _namespace_ and _access_. 998 999 When the _namespace_ format is used, MinIO synchronizes objects in the bucket with rows in the table. It creates rows with two columns: key_name and value. The key_name is the bucket and object name of an object that exists in MinIO. The value is JSON encoded event data about the operation that created/replaced the object in MinIO. When objects are updated or deleted, the corresponding row from this table is updated or deleted respectively. 1000 1001 When the _access_ format is used, MinIO appends events to a table. It creates rows with two columns: event_time and event_data. The event_time is the time at which the event occurred in the MinIO server. The event_data is the JSON encoded event data about the operation on an object. No rows are deleted or modified in this format. 1002 1003 The steps below show how to use this notification target in `namespace` format. The other format is very similar and is omitted for brevity. 1004 1005 ### Step 1: Ensure minimum requirements are met 1006 1007 MinIO requires MySQL version 5.7.8 or above. MinIO uses the [JSON](https://dev.mysql.com/doc/refman/5.7/en/json.html) data-type introduced in version 5.7.8. We tested this setup on MySQL 5.7.17. 1008 1009 ### Step 2: Add MySQL server endpoint configuration to MinIO 1010 1011 The MySQL configuration is located in the `notify_mysql` key. Create a configuration key-value pair here for your MySQL instance. The key is a name for your MySQL endpoint, and the value is a collection of key-value parameters described in the table below. 1012 1013 ``` 1014 KEY: 1015 notify_mysql[:name] publish bucket notifications to MySQL databases. When multiple MySQL server endpoints are needed, a user specified "name" can be added for each configuration, (e.g."notify_mysql:myinstance"). 1016 1017 ARGS: 1018 dsn_string* (string) MySQL data-source-name connection string e.g. "<user>:<password>@tcp(<host>:<port>)/<database>" 1019 table* (string) DB table name to store/update events, table is auto-created 1020 format* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 1021 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 1022 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 1023 max_open_connections (number) maximum number of open connections to the database, defaults to '2' 1024 comment (sentence) optionally add a comment to this setting 1025 ``` 1026 1027 or environment variables 1028 ``` 1029 KEY: 1030 notify_mysql[:name] publish bucket notifications to MySQL databases 1031 1032 ARGS: 1033 MINIO_NOTIFY_MYSQL_ENABLE* (on|off) enable notify_mysql target, default is 'off' 1034 MINIO_NOTIFY_MYSQL_DSN_STRING* (string) MySQL data-source-name connection string e.g. "<user>:<password>@tcp(<host>:<port>)/<database>" 1035 MINIO_NOTIFY_MYSQL_TABLE* (string) DB table name to store/update events, table is auto-created 1036 MINIO_NOTIFY_MYSQL_FORMAT* (namespace*|access) 'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace' 1037 MINIO_NOTIFY_MYSQL_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 1038 MINIO_NOTIFY_MYSQL_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 1039 MINIO_NOTIFY_MYSQL_MAX_OPEN_CONNECTIONS (number) maximum number of open connections to the database, defaults to '2' 1040 MINIO_NOTIFY_MYSQL_COMMENT (sentence) optionally add a comment to this setting 1041 ``` 1042 1043 > NOTE: If the `max_open_connections` key or the environment variable `MINIO_NOTIFY_MYSQL_MAX_OPEN_CONNECTIONS` is set to `0`, There will be no limit set on the number of 1044 > open connections to the database. This setting is generally NOT recommended as the behavior may be inconsistent during recursive deletes in `namespace` format. 1045 1046 `dsn_string` is required and is of form `"<user>:<password>@tcp(<host>:<port>)/<database>"` 1047 1048 MinIO supports persistent event store. The persistent store will backup events if MySQL connection goes offline and then replays the stored events when the broken connection comes back up. The event store can be configured by setting a directory path in `queue_dir` field, and the maximum number of events, which can be stored in a `queue_dir`, in `queue_limit` field. For example, `queue_dir` can be set to `/home/events` and `queue_limit` can be set to `1000`. By default, the `queue_limit` is set to `100000`. 1049 1050 Before updating the configuration, let's start with `mc admin config get` command to get the current configuration. 1051 1052 ```sh 1053 $ mc admin config get myminio/ notify_mysql 1054 notify_mysql:myinstance enable=off format=namespace host= port= username= password= database= dsn_string= table= queue_dir= queue_limit=0 1055 ``` 1056 1057 Use `mc admin config set` command to update MySQL notification configuration for the deployment with `dsn_string` parameter: 1058 1059 ```sh 1060 $ mc admin config set myminio notify_mysql:myinstance table="minio_images" dsn_string="root:xxxx@tcp(172.17.0.1:3306)/miniodb" 1061 ``` 1062 1063 Note that, you can add as many MySQL server endpoint configurations as needed by providing an identifier (like "myinstance" in the example above) for each MySQL instance desired. 1064 1065 Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::myinstance:mysql` at start-up, if there are no errors. 1066 1067 ### Step 3: Enable bucket notification using MinIO client 1068 1069 We will now setup bucket notifications on a bucket named `images`. Whenever a JPEG image object is created/overwritten, a new row is added or an existing row is updated in the MySQL table configured above. When an existing object is deleted, the corresponding row is deleted from the MySQL table. Thus, the rows in the MySQL table, reflect the `.jpg` objects in the `images` bucket. 1070 1071 To configure this bucket notification, we need the ARN printed by MinIO in the previous step. Additional information about ARN is available [here](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html). 1072 1073 With the `mc` tool, the configuration is very simple to add. Let us say that the MinIO server is aliased as `myminio` in our mc configuration. Execute the following: 1074 1075 ``` 1076 # Create bucket named `images` in myminio 1077 mc mb myminio/images 1078 # Add notification configuration on the `images` bucket using the MySQL ARN. The --suffix argument filters events. 1079 mc event add myminio/images arn:minio:sqs::myinstance:mysql --suffix .jpg 1080 # Print out the notification configuration on the `images` bucket. 1081 mc event list myminio/images 1082 arn:minio:sqs::myinstance:mysql s3:ObjectCreated:*,s3:ObjectRemoved:*,s3:ObjectAccessed:* Filter: suffix=”.jpg” 1083 ``` 1084 1085 ### Step 4: Test on MySQL 1086 1087 Open another terminal and upload a JPEG image into `images` bucket: 1088 1089 ``` 1090 mc cp myphoto.jpg myminio/images 1091 ``` 1092 1093 Open MySQL terminal and list the rows in the `minio_images` table. 1094 1095 ``` 1096 $ mysql -h 172.17.0.1 -P 3306 -u root -p miniodb 1097 mysql> select * from minio_images; 1098 +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1099 | key_name | value | 1100 +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1101 | images/myphoto.jpg | {"Records": [{"s3": {"bucket": {"arn": "arn:aws:s3:::images", "name": "images", "ownerIdentity": {"principalId": "minio"}}, "object": {"key": "myphoto.jpg", "eTag": "467886be95c8ecfd71a2900e3f461b4f", "size": 26, "sequencer": "14AC59476F809FD3"}, "configurationId": "Config", "s3SchemaVersion": "1.0"}, "awsRegion": "", "eventName": "s3:ObjectCreated:Put", "eventTime": "2017-03-16T11:29:00Z", "eventSource": "aws:s3", "eventVersion": "2.0", "userIdentity": {"principalId": "minio"}, "responseElements": {"x-amz-request-id": "14AC59476F809FD3", "x-minio-origin-endpoint": "http://192.168.86.110:9000"}, "requestParameters": {"sourceIPAddress": "127.0.0.1:38260"}}]} | 1102 +--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1103 1 row in set (0.01 sec) 1104 1105 ``` 1106 1107 <a name="apache-kafka"></a> 1108 1109 ## Publish MinIO events via Kafka 1110 1111 Install Apache Kafka from [here](http://kafka.apache.org/). 1112 1113 ### Step 1: Ensure minimum requirements are met 1114 1115 MinIO requires Kafka version 0.10 or 0.9. Internally MinIO uses the [Shopify/sarama](https://github.com/Shopify/sarama/) library and so has the same version compatibility as provided by this library. 1116 1117 ### Step 2: Add Kafka endpoint to MinIO 1118 1119 MinIO supports persistent event store. The persistent store will backup events when the kafka broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 1120 1121 ``` 1122 KEY: 1123 notify_kafka[:name] publish bucket notifications to Kafka endpoints 1124 1125 ARGS: 1126 brokers* (csv) comma separated list of Kafka broker addresses 1127 topic (string) Kafka topic used for bucket notifications 1128 sasl_username (string) username for SASL/PLAIN or SASL/SCRAM authentication 1129 sasl_password (string) password for SASL/PLAIN or SASL/SCRAM authentication 1130 sasl_mechanism (string) sasl authentication mechanism, default 'PLAIN' 1131 tls_client_auth (string) clientAuth determines the Kafka server's policy for TLS client auth 1132 sasl (on|off) set to 'on' to enable SASL authentication 1133 tls (on|off) set to 'on' to enable TLS 1134 tls_skip_verify (on|off) trust server TLS without verification, defaults to "on" (verify) 1135 client_tls_cert (path) path to client certificate for mTLS auth 1136 client_tls_key (path) path to client key for mTLS auth 1137 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 1138 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 1139 version (string) specify the version of the Kafka cluster e.g '2.2.0' 1140 comment (sentence) optionally add a comment to this setting 1141 ``` 1142 1143 or environment variables 1144 ``` 1145 KEY: 1146 notify_kafka[:name] publish bucket notifications to Kafka endpoints 1147 1148 ARGS: 1149 MINIO_NOTIFY_KAFKA_ENABLE* (on|off) enable notify_kafka target, default is 'off' 1150 MINIO_NOTIFY_KAFKA_BROKERS* (csv) comma separated list of Kafka broker addresses 1151 MINIO_NOTIFY_KAFKA_TOPIC (string) Kafka topic used for bucket notifications 1152 MINIO_NOTIFY_KAFKA_SASL_USERNAME (string) username for SASL/PLAIN or SASL/SCRAM authentication 1153 MINIO_NOTIFY_KAFKA_SASL_PASSWORD (string) password for SASL/PLAIN or SASL/SCRAM authentication 1154 MINIO_NOTIFY_KAFKA_SASL_MECHANISM (plain*|sha256|sha512) sasl authentication mechanism, default 'plain' 1155 MINIO_NOTIFY_KAFKA_TLS_CLIENT_AUTH (string) clientAuth determines the Kafka server's policy for TLS client auth 1156 MINIO_NOTIFY_KAFKA_SASL (on|off) set to 'on' to enable SASL authentication 1157 MINIO_NOTIFY_KAFKA_TLS (on|off) set to 'on' to enable TLS 1158 MINIO_NOTIFY_KAFKA_TLS_SKIP_VERIFY (on|off) trust server TLS without verification, defaults to "on" (verify) 1159 MINIO_NOTIFY_KAFKA_CLIENT_TLS_CERT (path) path to client certificate for mTLS auth 1160 MINIO_NOTIFY_KAFKA_CLIENT_TLS_KEY (path) path to client key for mTLS auth 1161 MINIO_NOTIFY_KAFKA_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 1162 MINIO_NOTIFY_KAFKA_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 1163 MINIO_NOTIFY_KAFKA_COMMENT (sentence) optionally add a comment to this setting 1164 MINIO_NOTIFY_KAFKA_VERSION (string) specify the version of the Kafka cluster e.g. '2.2.0' 1165 ``` 1166 1167 To update the configuration, use `mc admin config get` command to get the current configuration. 1168 1169 ```sh 1170 $ mc admin config get myminio/ notify_kafka 1171 notify_kafka:1 tls_skip_verify="off" queue_dir="" queue_limit="0" sasl="off" sasl_password="" sasl_username="" tls_client_auth="0" tls="off" brokers="" topic="" client_tls_cert="" client_tls_key="" version="" 1172 ``` 1173 1174 Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:kafka` at start-up if there were no errors.`bucketevents` is the topic used by kafka in this example. 1175 1176 ```sh 1177 $ mc admin config set myminio notify_kafka:1 tls_skip_verify="off" queue_dir="" queue_limit="0" sasl="off" sasl_password="" sasl_username="" tls_client_auth="0" tls="off" client_tls_cert="" client_tls_key="" brokers="localhost:9092,localhost:9093" topic="bucketevents" version="" 1178 ``` 1179 1180 ### Step 3: Enable bucket notification using MinIO client 1181 1182 We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted from `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:kafka`. To understand more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation. 1183 1184 ``` 1185 mc mb myminio/images 1186 mc event add myminio/images arn:minio:sqs::1:kafka --suffix .jpg 1187 mc event list myminio/images 1188 arn:minio:sqs::1:kafka s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 1189 ``` 1190 1191 ### Step 4: Test on Kafka 1192 1193 We used [kafkacat](https://github.com/edenhill/kafkacat) to print all notifications on the console. 1194 1195 ``` 1196 kafkacat -C -b localhost:9092 -t bucketevents 1197 ``` 1198 1199 Open another terminal and upload a JPEG image into `images` bucket. 1200 1201 ``` 1202 mc cp myphoto.jpg myminio/images 1203 ``` 1204 1205 `kafkacat` prints the event notification to the console. 1206 1207 ``` 1208 kafkacat -b localhost:9092 -t bucketevents 1209 { 1210 "EventName": "s3:ObjectCreated:Put", 1211 "Key": "images/myphoto.jpg", 1212 "Records": [ 1213 { 1214 "eventVersion": "2.0", 1215 "eventSource": "minio:s3", 1216 "awsRegion": "", 1217 "eventTime": "2019-09-10T17:41:54Z", 1218 "eventName": "s3:ObjectCreated:Put", 1219 "userIdentity": { 1220 "principalId": "AKIAIOSFODNN7EXAMPLE" 1221 }, 1222 "requestParameters": { 1223 "accessKey": "AKIAIOSFODNN7EXAMPLE", 1224 "region": "", 1225 "sourceIPAddress": "192.168.56.192" 1226 }, 1227 "responseElements": { 1228 "x-amz-request-id": "15C3249451E12784", 1229 "x-minio-deployment-id": "751a8ba6-acb2-42f6-a297-4cdf1cf1fa4f", 1230 "x-minio-origin-endpoint": "http://192.168.97.83:9000" 1231 }, 1232 "s3": { 1233 "s3SchemaVersion": "1.0", 1234 "configurationId": "Config", 1235 "bucket": { 1236 "name": "images", 1237 "ownerIdentity": { 1238 "principalId": "AKIAIOSFODNN7EXAMPLE" 1239 }, 1240 "arn": "arn:aws:s3:::images" 1241 }, 1242 "object": { 1243 "key": "myphoto.jpg", 1244 "size": 6474, 1245 "eTag": "430f89010c77aa34fc8760696da62d08-1", 1246 "contentType": "image/jpeg", 1247 "userMetadata": { 1248 "content-type": "image/jpeg" 1249 }, 1250 "versionId": "1", 1251 "sequencer": "15C32494527B46C5" 1252 } 1253 }, 1254 "source": { 1255 "host": "192.168.56.192", 1256 "port": "", 1257 "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0" 1258 } 1259 } 1260 ] 1261 } 1262 ``` 1263 1264 <a name="webhooks"></a> 1265 1266 ## Publish MinIO events via Webhooks 1267 1268 [Webhooks](https://en.wikipedia.org/wiki/Webhook) are a way to receive information when it happens, rather than continually polling for that data. 1269 1270 ### Step 1: Add Webhook endpoint to MinIO 1271 1272 MinIO supports persistent event store. The persistent store will backup events when the webhook goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 1273 1274 ``` 1275 KEY: 1276 notify_webhook[:name] publish bucket notifications to webhook endpoints 1277 1278 ARGS: 1279 endpoint* (url) webhook server endpoint e.g. http://localhost:8080/minio/events 1280 auth_token (string) opaque string or JWT authorization token 1281 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 1282 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 1283 client_cert (string) client cert for Webhook mTLS auth 1284 client_key (string) client cert key for Webhook mTLS auth 1285 comment (sentence) optionally add a comment to this setting 1286 ``` 1287 1288 or environment variables 1289 ``` 1290 KEY: 1291 notify_webhook[:name] publish bucket notifications to webhook endpoints 1292 1293 ARGS: 1294 MINIO_NOTIFY_WEBHOOK_ENABLE* (on|off) enable notify_webhook target, default is 'off' 1295 MINIO_NOTIFY_WEBHOOK_ENDPOINT* (url) webhook server endpoint e.g. http://localhost:8080/minio/events 1296 MINIO_NOTIFY_WEBHOOK_AUTH_TOKEN (string) opaque string or JWT authorization token 1297 MINIO_NOTIFY_WEBHOOK_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 1298 MINIO_NOTIFY_WEBHOOK_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 1299 MINIO_NOTIFY_WEBHOOK_COMMENT (sentence) optionally add a comment to this setting 1300 MINIO_NOTIFY_WEBHOOK_CLIENT_CERT (string) client cert for Webhook mTLS auth 1301 MINIO_NOTIFY_WEBHOOK_CLIENT_KEY (string) client cert key for Webhook mTLS auth 1302 ``` 1303 1304 ```sh 1305 $ mc admin config get myminio/ notify_webhook 1306 notify_webhook:1 endpoint="" auth_token="" queue_limit="0" queue_dir="" client_cert="" client_key="" 1307 ``` 1308 1309 Use `mc admin config set` command to update the configuration for the deployment. Here the endpoint is the server listening for webhook notifications. Save the settings and restart the MinIO server for changes to take effect. Note that the endpoint needs to be live and reachable when you restart your MinIO server. 1310 1311 ```sh 1312 $ mc admin config set myminio notify_webhook:1 queue_limit="0" endpoint="http://localhost:3000" queue_dir="" 1313 ``` 1314 1315 ### Step 2: Enable bucket notification using MinIO client 1316 1317 We will enable bucket event notification to trigger whenever a JPEG image is uploaded to `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:webhook`. To learn more about ARN please follow [AWS ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) documentation. 1318 1319 ``` 1320 mc mb myminio/images 1321 mc mb myminio/images-thumbnail 1322 mc event add myminio/images arn:minio:sqs::1:webhook --event put --suffix .jpg 1323 ``` 1324 1325 Check if event notification is successfully configured by 1326 1327 ``` 1328 mc event list myminio/images 1329 ``` 1330 1331 You should get a response like this 1332 1333 ``` 1334 arn:minio:sqs::1:webhook s3:ObjectCreated:* Filter: suffix=".jpg" 1335 ``` 1336 1337 ### Step 3: Test with Thumbnailer 1338 1339 We used [Thumbnailer](https://github.com/minio/thumbnailer) to listen for MinIO notifications when a new JPEG file is uploaded (HTTP PUT). Triggered by a notification, Thumbnailer uploads a thumbnail of new image to MinIO server. To start with, download and install Thumbnailer. 1340 1341 ``` 1342 git clone https://github.com/minio/thumbnailer/ 1343 npm install 1344 ``` 1345 1346 Then open the Thumbnailer config file at `config/webhook.json` and add the configuration for your MinIO server and then start Thumbnailer by 1347 1348 ``` 1349 NODE_ENV=webhook node thumbnail-webhook.js 1350 ``` 1351 1352 Thumbnailer starts running at `http://localhost:3000/`. Next, configure the MinIO server to send notifications to this URL (as mentioned in step 1) and use `mc` to set up bucket notifications (as mentioned in step 2). Then upload a JPEG image to MinIO server by 1353 1354 ``` 1355 mc cp ~/images.jpg myminio/images 1356 .../images.jpg: 8.31 KB / 8.31 KB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.00% 59.42 KB/s 0s 1357 ``` 1358 1359 Wait a few moments, then check the bucket’s contents with mc ls — you will see a thumbnail appear. 1360 1361 ``` 1362 mc ls myminio/images-thumbnail 1363 [2017-02-08 11:39:40 IST] 992B images-thumbnail.jpg 1364 ``` 1365 1366 <a name="NSQ"></a> 1367 1368 ## Publish MinIO events to NSQ 1369 1370 Install an NSQ Daemon from [here](https://nsq.io/). Or use the following Docker 1371 command for starting an nsq daemon: 1372 1373 ``` 1374 docker run --rm -p 4150-4151:4150-4151 nsqio/nsq /nsqd 1375 ``` 1376 1377 ### Step 1: Add NSQ endpoint to MinIO 1378 1379 MinIO supports persistent event store. The persistent store will backup events when the NSQ broker goes offline and replays it when the broker comes back online. The event store can be configured by setting the directory path in `queue_dir` field and the maximum limit of events in the queue_dir in `queue_limit` field. For eg, the `queue_dir` can be `/home/events` and `queue_limit` can be `1000`. By default, the `queue_limit` is set to 100000. 1380 1381 To update the configuration, use `mc admin config get` command to get the current configuration for `notify_nsq`. 1382 1383 ``` 1384 KEY: 1385 notify_nsq[:name] publish bucket notifications to NSQ endpoints 1386 1387 ARGS: 1388 nsqd_address* (address) NSQ server address e.g. '127.0.0.1:4150' 1389 topic* (string) NSQ topic 1390 tls (on|off) set to 'on' to enable TLS 1391 tls_skip_verify (on|off) trust server TLS without verification, defaults to "on" (verify) 1392 queue_dir (path) staging dir for undelivered messages e.g. '/home/events' 1393 queue_limit (number) maximum limit for undelivered messages, defaults to '100000' 1394 comment (sentence) optionally add a comment to this setting 1395 ``` 1396 1397 or environment variables 1398 ``` 1399 KEY: 1400 notify_nsq[:name] publish bucket notifications to NSQ endpoints 1401 1402 ARGS: 1403 MINIO_NOTIFY_NSQ_ENABLE* (on|off) enable notify_nsq target, default is 'off' 1404 MINIO_NOTIFY_NSQ_NSQD_ADDRESS* (address) NSQ server address e.g. '127.0.0.1:4150' 1405 MINIO_NOTIFY_NSQ_TOPIC* (string) NSQ topic 1406 MINIO_NOTIFY_NSQ_TLS (on|off) set to 'on' to enable TLS 1407 MINIO_NOTIFY_NSQ_TLS_SKIP_VERIFY (on|off) trust server TLS without verification, defaults to "on" (verify) 1408 MINIO_NOTIFY_NSQ_QUEUE_DIR (path) staging dir for undelivered messages e.g. '/home/events' 1409 MINIO_NOTIFY_NSQ_QUEUE_LIMIT (number) maximum limit for undelivered messages, defaults to '100000' 1410 MINIO_NOTIFY_NSQ_COMMENT (sentence) optionally add a comment to this setting 1411 ``` 1412 1413 ```sh 1414 $ mc admin config get myminio/ notify_nsq 1415 notify_nsq:1 nsqd_address="" queue_dir="" queue_limit="0" tls="off" tls_skip_verify="off" topic="" 1416 ``` 1417 1418 Use `mc admin config set` command to update the configuration for the deployment. Restart the MinIO server to put the changes into effect. The server will print a line like `SQS ARNs: arn:minio:sqs::1:nsq` at start-up if there were no errors. 1419 1420 ```sh 1421 $ mc admin config set myminio notify_nsq:1 nsqd_address="127.0.0.1:4150" queue_dir="" queue_limit="0" tls="off" tls_skip_verify="on" topic="minio" 1422 ``` 1423 1424 Note that, you can add as many NSQ daemon endpoint configurations as needed by providing an identifier (like "1" in the example above) for the NSQ instance and an object of per-server configuration parameters. 1425 1426 ### Step 2: Enable bucket notification using MinIO client 1427 1428 We will enable bucket event notification to trigger whenever a JPEG image is uploaded or deleted `images` bucket on `myminio` server. Here ARN value is `arn:minio:sqs::1:nsq`. 1429 1430 ``` 1431 mc mb myminio/images 1432 mc event add myminio/images arn:minio:sqs::1:nsq --suffix .jpg 1433 mc event list myminio/images 1434 arn:minio:sqs::1:nsq s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg” 1435 ``` 1436 1437 ### Step 3: Test on NSQ 1438 1439 The simplest test is to download `nsq_tail` from [nsq github](https://github.com/nsqio/nsq/releases) 1440 1441 ``` 1442 ./nsq_tail -nsqd-tcp-address 127.0.0.1:4150 -topic minio 1443 ``` 1444 1445 Open another terminal and upload a JPEG image into `images` bucket. 1446 1447 ``` 1448 mc cp gopher.jpg myminio/images 1449 ``` 1450 1451 You should receive the following event notification via NSQ once the upload completes. 1452 1453 ``` 1454 {"EventName":"s3:ObjectCreated:Put","Key":"images/gopher.jpg","Records":[{"eventVersion":"2.0","eventSource":"minio:s3","awsRegion":"","eventTime":"2018-10-31T09:31:11Z","eventName":"s3:ObjectCreated:Put","userIdentity":{"principalId":"21EJ9HYV110O8NVX2VMS"},"requestParameters":{"sourceIPAddress":"10.1.1.1"},"responseElements":{"x-amz-request-id":"1562A792DAA53426","x-minio-origin-endpoint":"http://10.0.3.1:9000"},"s3":{"s3SchemaVersion":"1.0","configurationId":"Config","bucket":{"name":"images","ownerIdentity":{"principalId":"21EJ9HYV110O8NVX2VMS"},"arn":"arn:aws:s3:::images"},"object":{"key":"gopher.jpg","size":162023,"eTag":"5337769ffa594e742408ad3f30713cd7","contentType":"image/jpeg","userMetadata":{"content-type":"image/jpeg"},"versionId":"1","sequencer":"1562A792DAA53426"}},"source":{"host":"","port":"","userAgent":"MinIO (linux; amd64) minio-go/v6.0.8 mc/DEVELOPMENT.GOGET"}}]} 1455 ```