dynamo-db
  1. dynamo-db-what-are-streams

What are Streams? - (DynamoDB Streams)

Heading h1

Streams are used to capture modifications in real-time by tracking the changes in DynamoDB tables and trigger events based on these changes.

Syntax

Here are the elements of the syntax for DynamoDB Streams:

{
  "TableName": "example-table",
  "StreamViewType": "NEW_AND_OLD_IMAGES",
  "StreamSpecification": {
    "StreamEnabled": true,
    "StreamViewType": "NEW_AND_OLD_IMAGES"
  }
}

Example

Assume that an item is added to a DynamoDB table called UsersTable where the primary key is UserID. Then a stream record will be generated with the following data:

{
  "eventID": "122e6e35-37c2-43d7-9ad8-ca8e4159a6e0",
  "eventName": "INSERT",
  "eventVersion": "1.1",
  "eventSource": "aws:dynamodb",
  "awsRegion": "us-west-2",
  "dynamodb": {
    "ApproximateCreationDateTime": 1498491130,
    "Keys": {
      "UserID": {
        "S": "123456789"
      }
    },
    "NewImage": {
      "username": {
        "S": "johndoe"
      },
      "password": {
        "S": "password123"
      }
    },
    "SequenceNumber": "100000000000037604800",
    "SizeBytes": 76,
    "StreamViewType": "NEW_AND_OLD_IMAGES"
  }
}

Output

The new item will be captured in the stream record as an object with its corresponding data.

Explanation

DynamoDB Streams is a feature that provides a time-ordered sequence of item-level modifications made to a table. Each modification is called a stream record. You can retrieve stream records from a shard using the GetShardIterator and GetRecords operations. When you enable a stream on a table, DynamoDB captures a stream record whenever any of the following events occur: Insert, Update, or Delete.

Use

DynamoDB Streams can be used to perform various operations such as:

  • Replication: Capture table updates and feed them to other services or databases.
  • Notification: Detect changes in a table, perform a specific action, and notify subscribers of updated information.
  • Backup and restore: Stream records can be captured to S3 for backup purposes.
  • Analytics: Stream data to services like Kinesis to analyze and gain insights.

Important Points

  • DynamoDB Streams is an optional feature for each table.
  • Streams records are durable, meaning they are stored until they are processed or expire after 24 hours.
  • A DynamoDB stream can have multiple shards.

Summary

DynamoDB Streams is a powerful feature of DynamoDB that tracks changes made to items stored in a table. Stream records are stored in a time-ordered sequence, enabling real-time data analysis and monitoring. DynamoDB streams can be used for various purposes such as replication, notification, backup and restore, and analytics.

Published on: