Publish MinIO events via Redis

Introduction

Minio server supports Amazon S3 compatible bucket event notification for following targets AMQP, Elasticsearch , Redis, nats.io, PostgreSQL and Apache Kafka. Part 3 of this blog series covers sending bucket notifications using Redis.

Steps to Configure Redis

I used Ubuntu Linux 16.04, latest Minio server binary & Redis PPA version 3.0.7 on my laptop for this setup.

$ sudo add-apt-repository ppa:chris-lea/redis-server
$ sudo apt-get update
$ sudo apt-get install redis-server

You can alternatively install Redis from official website

Modify Redis server configuration file “/etc/redis/redis.conf” to enable access with password.

requirepass yoursecret

Restart Redis server.

$ sudo service redis-server restart

Steps to Configure Minio

Latest Minio server binary can be downloaded from https://minio.io/downloads/

$ wget https://dl.minio.io/server/minio/release/linux-amd64/minio
$ chmod +x minio

In this case “myphotos” is used as my data directory for Minio server.

$ ./minio server myphotos
Endpoint: http://10.1.10.150:9000 http://127.0.0.1:9000
AccessKey: 7I6R5G576YI641GS9J9F
SecretKey: SuycBIe+O/s5zXxU9w+N4wkXHpBCKa2H6Ptlrc8c
Region: us-east-1
...
...

The default location of Minio server configuration file is ~/.minio/config.json. Update the Redis configuration block in ‘config.json’ as follows

"redis": {
			"1": {
				"enable": true,
				"address": "127.0.0.1:6379",
				"password": "yoursecret",
				"key": "bucketevents"
			}
		}

Restart the Minio server to reflect config changes made above. “bucketevents” is the key used by Redis in this example.

Enable bucket notification using Minio client

Step 1: Download and install Minio client

$ wget https://dl.minio.io/client/mc/release/linux-amd64/mc
$ chmod 755 mc

Step 2: Add Minio server host alias information

Configure Minio client with access and secret keys pointing to the Minio server.

$ ./mc config host add myminio http://localhost:9000 7I6R5G576YI641GS9J9F SuycBIe+O/s5zXxU9w+N4wkXHpBCKa2H6Ptlrc8c

Step 3: Setup bucket notification

In this example we will enable bucket events only when JPEG images are uploaded or deleted from ‘images’ bucket on ‘myminio’ server. Here ARN value is arn:minio:sqs:us-east-1:1:redis. To understand more about ARN please follow AWS ARN documentation.

$ ./mc mb myminio/images
$ ./mc events add  myminio/images arn:minio:sqs:us-east-1:1:redis --suffix .jpg
$ ./mc events list myminio/images
arn:minio:sqs:us-east-1:1:redis s3:ObjectCreated:*,s3:ObjectRemoved:* Filter: suffix=”.jpg”

Step 4: Testing on Redis

Redis comes with handy command line interface, redis-cli. It uses “monitor” command to print all notification on console.

$ redis-cli -a yoursecret
127.0.0.1:6379> monitor
OK

Open another terminal and upload a JPEG image into “images” bucket.

$ ./mc cp myphoto.jpg myminio/images

Below “redis-cli” prints event notification on console.

For further questions and comments join our Slack chat at: https://slack.minio.io