Bird
Raised Fist0
DynamoDBquery~5 mins

Stream record types (NEW_IMAGE, OLD_IMAGE) in DynamoDB

Choose your learning style10 modes available
Introduction

Stream record types help you see what changed in your database. They show the data before and after an update.

You want to track changes to items in your DynamoDB table.
You need to react when a new item is added or an existing item is updated.
You want to keep a backup of old data before it changes.
You want to audit who changed what and when in your database.
Syntax
DynamoDB
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.

Examples
This stream record shows the new version of the item after an insert or update.
DynamoDB
StreamViewType: 'NEW_IMAGE'
NewImage: { "id": "123", "name": "Alice" }
This stream record shows the old version of the item before it was changed or deleted.
DynamoDB
StreamViewType: 'OLD_IMAGE'
OldImage: { "id": "123", "name": "Bob" }
This stream record shows both old and new versions, useful for comparing changes.
DynamoDB
StreamViewType: 'NEW_AND_OLD_IMAGES'
NewImage: { "id": "123", "name": "Alice" }
OldImage: { "id": "123", "name": "Bob" }
Sample Program

This example shows a stream record where the item with id 123 changed its name from Bob to Alice.

DynamoDB
-- 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"
}
OutputSuccess
Important Notes

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.

Summary

Stream record types show data before and/or after changes.

NEW_IMAGE shows the updated data.

OLD_IMAGE shows the data before the change.

Practice

(1/5)
1. What does the NEW_IMAGE stream record type represent in DynamoDB Streams?
easy
A. The updated data after a change has occurred
B. The data before any change was made
C. Only the keys of the changed item
D. A snapshot of the entire table

Solution

  1. Step 1: Understand the purpose of NEW_IMAGE

    NEW_IMAGE captures the state of the item after it has been modified.
  2. Step 2: Compare with other stream record types

    OLD_IMAGE shows the state before the change, so NEW_IMAGE must be the updated data.
  3. Final Answer:

    The updated data after a change has occurred -> Option A
  4. Quick Check:

    NEW_IMAGE = updated data [OK]
Hint: NEW_IMAGE means data after change [OK]
Common Mistakes:
  • Confusing NEW_IMAGE with OLD_IMAGE
  • Thinking NEW_IMAGE shows keys only
  • Assuming NEW_IMAGE is a full table snapshot
2. Which of the following is the correct way to specify that a DynamoDB stream should include the old image of items?
easy
A. "StreamViewType": "NEW_IMAGE"
B. "StreamViewType": "KEYS_ONLY"
C. "StreamViewType": "OLD_IMAGE"
D. "StreamViewType": "ALL_IMAGES"

Solution

  1. Step 1: Identify the correct StreamViewType for old data

    The option to capture the data before changes is OLD_IMAGE.
  2. Step 2: Match the option string

    "StreamViewType": "OLD_IMAGE" correctly uses "OLD_IMAGE" as the StreamViewType.
  3. Final Answer:

    "StreamViewType": "OLD_IMAGE" -> Option C
  4. Quick Check:

    Old data = OLD_IMAGE [OK]
Hint: OLD_IMAGE means data before change [OK]
Common Mistakes:
  • Using NEW_IMAGE instead of OLD_IMAGE
  • Confusing KEYS_ONLY with OLD_IMAGE
  • Using ALL_IMAGES which includes both images
3. Given a DynamoDB stream record with eventName as "MODIFY" and the following data:
{
  "OldImage": {"id": {"S": "123"}, "status": {"S": "pending"}},
  "NewImage": {"id": {"S": "123"}, "status": {"S": "completed"}}
}

What does the NewImage show?
medium
A. The item after the status was changed to completed
B. The item before the status was changed to completed
C. Only the id of the item
D. The entire table data

Solution

  1. Step 1: Understand the meaning of NewImage in MODIFY event

    NewImage shows the item after the update, so it reflects the new status "completed".
  2. Step 2: Compare OldImage and NewImage

    OldImage has status "pending", NewImage has status "completed" showing the update.
  3. Final Answer:

    The item after the status was changed to completed -> Option A
  4. Quick Check:

    NewImage = updated item [OK]
Hint: NewImage shows updated item after change [OK]
Common Mistakes:
  • Mixing OldImage and NewImage meanings
  • Thinking NewImage shows only keys
  • Assuming NewImage is unchanged data
4. You have a DynamoDB stream configured with StreamViewType set to NEW_IMAGE. You try to access OldImage in your Lambda function but get an error. What is the most likely cause?
medium
A. The Lambda function code has a syntax error
B. The stream is disabled
C. The table does not have a primary key
D. The stream does not include old images, so OldImage is missing

Solution

  1. Step 1: Understand StreamViewType effect on stream data

    If StreamViewType is NEW_IMAGE, only new images are included, so OldImage is not available.
  2. Step 2: Reason about the error cause

    Trying to access OldImage when it is not in the stream causes an error.
  3. Final Answer:

    The stream does not include old images, so OldImage is missing -> Option D
  4. Quick Check:

    StreamViewType limits images available [OK]
Hint: OldImage missing if StreamViewType is NEW_IMAGE [OK]
Common Mistakes:
  • Blaming Lambda code syntax
  • Ignoring stream configuration
  • Assuming primary key affects images
5. You want to track changes in a DynamoDB table and log both the old and new states of items whenever they are updated. Which StreamViewType should you configure, and why?
hard
A. NEW_IMAGE, because it shows the updated data only
B. NEW_AND_OLD_IMAGES, because it includes both before and after states
C. KEYS_ONLY, because it tracks only the primary keys
D. OLD_IMAGE, because it shows the data before changes

Solution

  1. Step 1: Identify requirement to log both old and new states

    To log both before and after states, the stream must include both images.
  2. Step 2: Match requirement to StreamViewType

    Only NEW_AND_OLD_IMAGES includes both old and new images in the stream.
  3. Final Answer:

    NEW_AND_OLD_IMAGES, because it includes both before and after states -> Option B
  4. Quick Check:

    Both images = NEW_AND_OLD_IMAGES [OK]
Hint: Use NEW_AND_OLD_IMAGES to get both states [OK]
Common Mistakes:
  • Choosing only NEW_IMAGE or OLD_IMAGE
  • Confusing KEYS_ONLY with full images
  • Not knowing NEW_AND_OLD_IMAGES exists
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard