Skip to content

Instantly share code, notes, and snippets.

@koolhead17
Created January 7, 2017 06:15
Show Gist options
  • Save koolhead17/2acbfdf458281b8254caab4afef130e4 to your computer and use it in GitHub Desktop.
Save koolhead17/2acbfdf458281b8254caab4afef130e4 to your computer and use it in GitHub Desktop.
var Minio = require('minio')
// Instantiate the minio client with the endpoint
// and access keys as shown below.
var minioClient = new Minio.Client({
endPoint: 'play.minio.io',
port: 9000,
secure: true,
accessKey: 'Q3AM3UQ867SPQQA43P2F',
secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
});
// Start listening for notifications on the bucket, using our arn.
var poller = minioClient.listenBucketNotification('atuljha', 'img-', '.jpg', ['s3:ObjectCreated:*'])
// Notification will be emitted every time a new notification is received.
// For object creation, here is a sample record:
// { eventVersion: '2.0',
// eventSource: 'aws:s3',
// awsRegion: 'us-east-1',
// eventTime: '2016-08-23T18:26:07.214Z',
// eventName: 's3:ObjectCreated:Put',
// userIdentity: { principalId: 'minio' },
// requestParameters: { sourceIPAddress: '...' },
// responseElements: {},
// s3:
// { s3SchemaVersion: '1.0',
// configurationId: 'Config',
// bucket:
// { name: 'bucket1',
// ownerIdentity: [Object],
// arn: 'arn:aws:s3:::bucket1' },
// object: { key: 'photos%2Fobject.jpg', size: 10, sequencer: '...' } } }
poller.on('notification', record => {
console.log('New object: %s/%s (size: %d)', record.s3.bucket.name,
record.s3.object.key, record.s3.object.size)
// Now that we've received our notification, we can cancel the listener.
// We could leave it open if we wanted to continue to receive notifications.
poller.stop()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment