ddb-stream-listener
This library is used to attach lambda functions to your dynamoDB streams.
It is used to create event types and attach custom handlers to them.
To use this library create a class such as:
How to use
const EventSourceBase = EventSourceBase; const TABLE_NAME = 'Events'; { superTABLE_NAME entityId eventType payload params; } static { return entityId eventType payload params; } moduleexports = Event;
This assumes that you have created a table named Events
with with streams enabled.
To create an event you declare an eventType eg:
const EVENT_TYPES = EXAMPLE_EVENT: 'example-event';
Import your new event type to where it will be used:
const Event = ;const EXAMPLE_EVENT = EVENT_TYPES;
The event object has a save
method that takes in the following parameters:
await Event;
To pick up events written to our Events
table we need to create a lambda function (AWS)
and attach it to the event stream of the Events Table
The following syntax is used with the
onEvent: handler: src/events/stream.onEvent events: - stream: type: dynamodb arn: Fn::GetAtt: - EventsDynamoDbTable - StreamArn
The onEvent
function can be declared as:
const StreamListener = StreamListener;const EXAMPLE_EVENT = EVENT_TYPES;const listener = ; exportsonEvent = async { try return await listener; catch error log; throw error; }; listener; { try await ; await ; return event; catch error throw error; }
And thats it! You know have a lambda that subscribes to events written to an dynamoDb table.