# DynamoDB Streams

* Streams here are ordered list of item-level modification i.e., *(create/update/delete)* in a table.
* Stream records can be sent to,
  * Kinesis Data Streams
  * AWS Lambda
  * KCL Applications
* **Data Retention for upto 24 hours**
* Use cases include,
  * React to changes in real-time.
  * Analytics
  * Insert into derivative tables.
  * Insert into OpenSearch service.
  * Implement cross-region replication.
* Provides ability to choose the information that will be written to streams. The information includes,

  | Attribute Name       | Description                                             |
  | -------------------- | ------------------------------------------------------- |
  | `KEYS_ONLY`          | Only attributes that will be modified                   |
  | `NEW_IMAGE`          | The entire items, as it appears after it was modified.  |
  | `OLD_IMAGE`          | The entire items, as it appears before it was modified. |
  | `NEW_AND_OLD_IMAGES` | Both new and old images of the item.                    |
* Streams are made of shards, just like `Kinesis Data Streams`.
* You don't need to provisions shards, this is automated by AWS.
* Records are not retroactively populated in a stream after enabling it.

## Integration with Lambda - Trigger

* Define an Event Source Mapping to read from a DynamoDB Streams.
* You need to ensure the lambda function have appropriate function.
* Event Source Mapping will poll the data from the DynamoDB streams.
* Trigger need to be set up so that lambda will be triggered.
* Once above set up is done, Lambda will be ready to invoked synchronously for a batch of record fetched from DynamoDB streams.
* Batch size, Starting position and Batch window needs to be configured, that many records will be collected at once before triggerring a lambda invocation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anon-coders-notes.gitbook.io/techwriterdev/cloud/aws/developerassociate/services/20_dynamodb/04_streams.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
