Introduction
Stream record types help you see what changed in your database. They show the data before and after an update.
Stream record types help you see what changed in your database. They show the data before and after an update.
StreamRecord {
Keys: { ... },
NewImage: { ... },
OldImage: { ... },
StreamViewType: 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES' | 'KEYS_ONLY'
}NewImage shows the item after the change.
OldImage shows the item before the change.
StreamViewType: 'NEW_IMAGE' NewImage: { "id": "123", "name": "Alice" }
StreamViewType: 'OLD_IMAGE' OldImage: { "id": "123", "name": "Bob" }
StreamViewType: 'NEW_AND_OLD_IMAGES' NewImage: { "id": "123", "name": "Alice" } OldImage: { "id": "123", "name": "Bob" }
This example shows a stream record where the item with id 123 changed its name from Bob to Alice.
-- Assume DynamoDB stream is enabled with NEW_AND_OLD_IMAGES -- Sample stream record for an update { "Keys": { "id": { "S": "123" } }, "NewImage": { "id": { "S": "123" }, "name": { "S": "Alice" } }, "OldImage": { "id": { "S": "123" }, "name": { "S": "Bob" } }, "StreamViewType": "NEW_AND_OLD_IMAGES" }
Stream records only appear if you enable DynamoDB Streams on your table.
Choose the StreamViewType based on what data you want to capture: keys only, new image, old image, or both.
Stream record types show data before and/or after changes.
NEW_IMAGE shows the updated data.
OLD_IMAGE shows the data before the change.
NEW_IMAGE stream record type represent in DynamoDB Streams?NEW_IMAGENEW_IMAGE captures the state of the item after it has been modified.OLD_IMAGE shows the state before the change, so NEW_IMAGE must be the updated data.NEW_IMAGE = updated data [OK]OLD_IMAGE.eventName as "MODIFY" and the following data:{
"OldImage": {"id": {"S": "123"}, "status": {"S": "pending"}},
"NewImage": {"id": {"S": "123"}, "status": {"S": "completed"}}
}NewImage show?StreamViewType set to NEW_IMAGE. You try to access OldImage in your Lambda function but get an error. What is the most likely cause?StreamViewType should you configure, and why?NEW_AND_OLD_IMAGES includes both old and new images in the stream.Pass the test and this pattern moves unknown