DynamoDB Streams

 

DynamoDB Streams are one of the most powerful—but often under‑explained—features in DynamoDB.

A DynamoDB Stream captures every change to items in a table:

  • INSERT
  • MODIFY
  • REMOVE

You can then process these changes using:

  • AWS Lambda
  • Kinesis
  • Custom consumers

This is how you build event‑driven architectures with DynamoDB.

Enable Streams on the Table:

You choose a stream view type, e.g.:

  • NEW_IMAGE → only the new item
  • OLD_IMAGE → only the old item
  • NEW_AND_OLD_IMAGES → both
  • KEYS_ONLY → only keys
I have table created by the name called "order".



I have enabled "Streams" to capture the changes to the table.


And I have added the lambda function to process the streams.

Lambda gets triggered, whenever there is a change in the DB items.

Below is the lambda snippet:

import json

def lambda_handler(event, context):
    for record in event["Records"]:
        event_name = record["eventName"]
        keys = record["dynamodb"]["Keys"]

        if event_name == "INSERT":
            new = record["dynamodb"]["NewImage"]
            print("New order:", new)

        elif event_name == "MODIFY":
            old = record["dynamodb"]["OldImage"]
            new = record["dynamodb"]["NewImage"]
            print("Order updated:", old, "→", new)

        elif event_name == "REMOVE":
            old = record["dynamodb"]["OldImage"]
            print("Order deleted:", old)

It captures the DynamoDB changes like "INSERT", "MODIFY" and "REMOVE".

Let's modify the order_name from Sam to John.

Once we made the changes, we can look at the CloudWatch logs for the stream changes.



Comments

Popular posts from this blog

K8s - ETCD

Agentic AI - Series 3

Agentic AI - Series 4