@moblybr/node-s3-event-bus
v1.1.0
Published
A package to use event bus with S3 service in AWS
Downloads
4
Keywords
Readme
@mobly/packages/node/s3-event-bus
Package with s3 event bus implementation for mobly projects.
Installation
To install a package:
npm i @moblybr/node-s3-event-bus
Usage
Publish Event
To publish a event you need to send a message, passing a bucket name, service, bucket path, bucket region and message (string, object).
src/publishEvent.js
const { publishEvent } = require('@moblybr/node-s3-event-bus')
const handler = middy(async (event, context) => {
const params = {
bucket: 'tester-bucket',
service: 'tester-service',
path: 'create',
body: { name: 'User', birthDate: '1990-05-10' },
configS3: { region: 'us-east-1' }
}
await publishEvent(params)
...
}
Get Event
To get a event you, need to retrieve the message by passing the key, bucket name and bucket region.
You can retrieve the event keyt in the context object.
src/getEvent.js
const { getEvent } = require('@moblybr/node-s3-event-bus')
const handler = middy(async (event, context) => {
const params = {
key: 'key',
bucket: 'tester-bucket',
configS3: {
region: 'us-east-1'
}
}
const result = await getEvent(params)
const parsedResult = JSON.parse(result.Body.toString('utf-8'))
...
}