Dynamo Types Stream
Framework for DynamoDB Stream Event processing on Lambda. Based on (https://github.com/balmbees/dynamo-typeorm) Powering Vingle
What is this for?
When you're using DynamoDB, it's common pattern to connect DynamoDB Stream to Lambda to do data change based background works.
For example, Let's say you want to send notification to slack when new DynamooDB Record is inserted
Then commonly, you connect DynamoDB Stream to lambda and wrote
But clearly, there are some missing things here,
1) DynamoDB Record Parsing (ORM)
Raw event format for DynamoDB Stream is pretty complicated.
{ a: 100 } represented as { a: { N: 100 } }, and there are many other things you need know how to parse
2) Error Handling
It's also common to connect several background process for single table.
For example, let's say you want to
a. Get slack notification when new record inserted
b. Backup the record to S3 if the record removed
Then you would wrote code like
And this is really dangerous if backuptoS3
throws Error.
In that case, whole Lambda invocation go to error, thus this batch of DynamoDB Stream events marked as failed.
And when DynamoDB Stream failed to process some events, it retries with same events until either events expires (24 hours after created) or process successed
So if there is bug on backuptoS3
, you'll get slack notification infinitely
To avoid this, you should do something like
Not that cool right?
Usage
; // First Define your DynamoDB Table ; // This is lambda event handler. "exports.handler"
And createLambdaHandler
is optional as you can imagine. if you already have your own wrapper for lambda function
you might only use createHandler
, which is (event: LambdaEvent) => Promise<void>
/** * * @param tableClass DynamoTypes Class * @param strategy handler Execution strategy. Map execute all handlers once, Series excute handlers one by one * @param handlers */