Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can you use dynamodb streams to have realtime triggers like firebase?

Looking through the new dynamodb streams feature, can you use it to do real-time push scenarios like a chat room? Or can you only poll the streams api to get periodic updates?

It seems like the only examples show dynamodb connected to a kinesis stream to make it real time push rather than through polling.

Taking the chat room example even further, can you call the dynamodb streams api "GetRecords" with a filter clause so that you only get the records for a specific hash or range?

What is a "ShardIterator?" Reading through the documentation, it's unclear what it's specifically used for.

like image 927
MonkeyBonkey Avatar asked Jul 24 '15 19:07

MonkeyBonkey


People also ask

Are DynamoDB streams real time?

The events generated by DynamoDB Streams are near-real-time but not real-time.

Does DynamoDB have triggers?

Amazon DynamoDB is integrated with AWS Lambda so that you can create triggers—pieces of code that automatically respond to events in DynamoDB Streams. With triggers, you can build applications that react to data modifications in DynamoDB tables.

What is DynamoDB streams used for?

A DynamoDB stream is an ordered flow of information about changes to items in a DynamoDB table. When you enable a stream on a table, DynamoDB captures information about every modification to data items in the table.

Can DynamoDB streams trigger Lambda?

With DynamoDB Streams, you can trigger a Lambda function to perform additional work each time a DynamoDB table is updated. Lambda reads records from the stream and invokes your function synchronously with an event that contains stream records.


2 Answers

Now that AWS IoT is available, you could do DynamoDB Streams > Lambda > AWS IoT > Browser over MQTT or Websockets. This works both ways - with the return path being simpler as AWS IoT can post to Dynamodb directly.

Lambda receives a list of records from Dynamodb Streams and you can loop over the list and publish data to appropriate clients using MQTT topics structured per chat or user (/chat/{uuid} or /chat/joe).

like image 85
Tej Pochiraju Avatar answered Oct 24 '22 19:10

Tej Pochiraju


DynamoDB Streams are very, very similar to Kinesis but technically different things. They use similar APIs and their client libraries are related as well, but they are different.

It sounds like you are waiting a client (ex: browser) running on a client to receive a notification that a record changed in real time. This is not what DynamoDB Streams provides.

DynamoDB Streams are more like the NoSQL+clouds approach to database triggers.

It would be possible to build something similar to Firebase using DynamoDB + DynamoDB Streams + Lambda + some type of web socket server. Using this approach you could have writes to your DynamoDB database notify a Lambda function that would notify a web socket server that clients are connected to in real time. This means DynamoDB Streams + Lambda really isn't doing the heavy lifting for this use case as you would need to run your own web sockets server on EC2.

like image 43
JaredHatfield Avatar answered Oct 24 '22 19:10

JaredHatfield