Bird
Raised Fist0
DynamoDBquery~10 mins

Stream processing patterns in DynamoDB - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read records from a DynamoDB stream.

DynamoDB
for record in event['Records']:
    print(record['[1]'])
Drag options to blanks, or click blank then click option'
AeventName
BstreamViewType
CawsRegion
Ddynamodb
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dynamodb' instead of 'eventName' will print the whole DynamoDB data, not the event type.
Using 'streamViewType' or 'awsRegion' does not give the event type.
2fill in blank
medium

Complete the code to get the new image of the changed item from the stream record.

DynamoDB
new_image = record['dynamodb']['[1]']
Drag options to blanks, or click blank then click option'
AOldImage
BKeys
CNewImage
DSequenceNumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'OldImage' will give the previous state, not the new one.
Using 'Keys' or 'SequenceNumber' does not provide the item data.
3fill in blank
hard

Fix the error in the code to check if the event is an INSERT.

DynamoDB
if record['eventName'] == '[1]':
    print('New item inserted')
Drag options to blanks, or click blank then click option'
AREMOVE
BINSERT
CUPDATE
DMODIFY
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'UPDATE' or 'MODIFY' instead of 'INSERT' will not detect new items.
Using 'REMOVE' checks for deletions, not insertions.
4fill in blank
hard

Fill both blanks to filter stream records for MODIFY events and get the old image.

DynamoDB
if record['[1]'] == 'MODIFY':
    old_image = record['dynamodb']['[2]']
Drag options to blanks, or click blank then click option'
AeventName
BNewImage
COldImage
DKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NewImage' instead of 'OldImage' will give the updated data, not the old.
Checking 'Keys' instead of 'eventName' will not filter events.
5fill in blank
hard

Fill all three blanks to create a dictionary of item keys and their new values for INSERT events.

DynamoDB
if record['[1]'] == 'INSERT':
    new_image = record['dynamodb']['[2]']
    keys = {k: v['[3]'] for k, v in new_image.items()}
Drag options to blanks, or click blank then click option'
AeventName
BNewImage
CS
DOldImage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'OldImage' instead of 'NewImage' will get old data.
Using 'N' or other keys instead of 'S' will not extract string values correctly.

Practice

(1/5)
1. What is the main purpose of using DynamoDB Streams in stream processing patterns?
easy
A. To capture and react to data changes in real time
B. To store large amounts of data permanently
C. To create backups of the database
D. To improve query speed by indexing

Solution

  1. Step 1: Understand DynamoDB Streams role

    DynamoDB Streams capture data changes like inserts, updates, and deletes as they happen.
  2. Step 2: Identify the purpose in stream processing

    Streams allow applications to react immediately to these changes, enabling real-time processing.
  3. Final Answer:

    To capture and react to data changes in real time -> Option A
  4. Quick Check:

    Streams = real-time data reaction [OK]
Hint: Streams track changes instantly for real-time reactions [OK]
Common Mistakes:
  • Confusing Streams with data storage
  • Thinking Streams create backups
  • Assuming Streams speed up queries
2. Which of the following is the correct way to enable a DynamoDB Stream on a table?
easy
A. Create a global secondary index with Streams enabled
B. Add a Lambda trigger without enabling Streams
C. Set StreamSpecification with StreamEnabled = true and StreamViewType
D. Use the UpdateItem API to activate Streams

Solution

  1. Step 1: Recall how to enable Streams

    Streams are enabled by setting the StreamSpecification property on the table with StreamEnabled set to true and choosing a StreamViewType.
  2. Step 2: Evaluate options

    Set StreamSpecification with StreamEnabled = true and StreamViewType correctly describes enabling Streams. The other options do not enable Streams properly.
  3. Final Answer:

    Set StreamSpecification with StreamEnabled = true and StreamViewType -> Option C
  4. Quick Check:

    Enable Streams via StreamSpecification [OK]
Hint: Enable Streams in table settings, not via Lambda or indexes [OK]
Common Mistakes:
  • Trying to enable Streams via Lambda triggers
  • Confusing Streams with indexes
  • Using UpdateItem API to enable Streams
3. Given a DynamoDB Stream enabled with NEW_IMAGE view type, what will a Lambda function receive when an item is updated?
medium
A. Only the old item image before the update
B. Only the new item image after the update
C. Both old and new item images
D. No item images, only keys

Solution

  1. Step 1: Understand StreamViewType NEW_IMAGE

    NEW_IMAGE means the stream records contain the item as it appears after the change.
  2. Step 2: Determine what Lambda receives on update

    Lambda gets the new item image only, not the old one or both.
  3. Final Answer:

    Only the new item image after the update -> Option B
  4. Quick Check:

    NEW_IMAGE = new item data only [OK]
Hint: NEW_IMAGE streams send updated item data only [OK]
Common Mistakes:
  • Confusing NEW_IMAGE with OLD_IMAGE or BOTH_IMAGES
  • Expecting both old and new images
  • Assuming keys only are sent
4. A developer wrote a Lambda function triggered by DynamoDB Streams but it never processes any records. What is the most likely cause?
medium
A. The DynamoDB table does not have Streams enabled
B. The Lambda function code has a syntax error
C. The table has no data at all
D. The Lambda function timeout is too long

Solution

  1. Step 1: Check Stream enablement

    If Streams are not enabled on the table, no events trigger Lambda.
  2. Step 2: Evaluate other options

    Syntax errors cause failures but do not prevent invocation. No data means no changes, but usually there are some. Timeout too long does not stop invocation.
  3. Final Answer:

    The DynamoDB table does not have Streams enabled -> Option A
  4. Quick Check:

    Streams must be enabled for Lambda triggers [OK]
Hint: Check if Streams are enabled before debugging Lambda code [OK]
Common Mistakes:
  • Assuming code errors stop Lambda from triggering
  • Ignoring Streams enablement
  • Thinking timeout affects event triggering
5. You want to build a system that sends notifications only when a specific attribute "status" changes in DynamoDB items. Which stream processing pattern best fits this requirement?
hard
A. Use Streams with OLD_IMAGE view type only
B. Disable Streams and poll the table periodically
C. Enable Streams with KEYS_ONLY view type and check keys in Lambda
D. Filter and transform stream records in Lambda to detect "status" changes

Solution

  1. Step 1: Understand the need to detect attribute changes

    To detect changes in "status", you need both old and new values to compare.
  2. Step 2: Choose the right pattern

    Filtering and transforming stream records in Lambda lets you compare old and new images and trigger notifications only on "status" changes.
  3. Step 3: Evaluate other options

    OLD_IMAGE alone lacks new data, KEYS_ONLY lacks attribute data, polling is inefficient and not real-time.
  4. Final Answer:

    Filter and transform stream records in Lambda to detect "status" changes -> Option D
  5. Quick Check:

    Filter stream records in Lambda for attribute changes [OK]
Hint: Compare old and new images in Lambda to detect attribute changes [OK]
Common Mistakes:
  • Using KEYS_ONLY which lacks attribute data
  • Relying on OLD_IMAGE without new data
  • Polling instead of using Streams
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