Bird
Raised Fist0
DynamoDBquery~10 mins

Basic scan operation in DynamoDB - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to scan all items from the DynamoDB table named 'Products'.

DynamoDB
response = dynamodb_client.[1](TableName='Products')
Drag options to blanks, or click blank then click option'
Ascan
Bquery
Cget_item
Dput_item
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' instead of 'scan' will not return all items.
Using 'get_item' only fetches one item by key.
2fill in blank
medium

Complete the code to scan the 'Users' table and get only the 'UserId' and 'Email' attributes.

DynamoDB
response = dynamodb_client.scan(TableName='Users', ProjectionExpression='[1]')
Drag options to blanks, or click blank then click option'
AUserId; Email
BUserId Email
C'UserId, Email'
DUserId, Email
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of commas between attribute names.
Adding quotes inside the string causing syntax errors.
3fill in blank
hard

Fix the error in the scan call to filter items where 'Status' equals 'Active'.

DynamoDB
response = dynamodb_client.scan(TableName='Orders', FilterExpression='[1] = :status', ExpressionAttributeValues={':status': {'S': 'Active'}})
Drag options to blanks, or click blank then click option'
A#Status
Bstatus
CStatus
D:Status
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':Status' which is for values, not attribute names.
Using '#Status' without defining ExpressionAttributeNames.
4fill in blank
hard

Fill both blanks to scan the 'Employees' table and return only employees with 'Age' greater than 30.

DynamoDB
response = dynamodb_client.scan(TableName='Employees', FilterExpression='[1] > :age', ExpressionAttributeValues={':age': {'N': '[2]'}})
Drag options to blanks, or click blank then click option'
AAge
B30
CAgeGroup
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute name like 'AgeGroup'.
Using incorrect number value in ExpressionAttributeValues.
5fill in blank
hard

Fill all three blanks to scan the 'Books' table, projecting 'Title' and 'Author', and filtering books published after 2010.

DynamoDB
response = dynamodb_client.scan(TableName='Books', ProjectionExpression='[1], [2]', FilterExpression='[3] > :year', ExpressionAttributeValues={':year': {'N': '2010'}})
Drag options to blanks, or click blank then click option'
ATitle
BAuthor
CPublishedYear
DYear
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names in projection or filter.
Mixing attribute names with values.

Practice

(1/5)
1. What does the scan operation do in DynamoDB?
easy
A. Reads all items in a table
B. Reads only one item by key
C. Deletes items from a table
D. Updates items in a table

Solution

  1. Step 1: Understand the scan operation

    The scan operation reads every item in the DynamoDB table without filtering by key.
  2. Step 2: Compare with other operations

    Unlike get or query, scan reads all items, not just specific keys.
  3. Final Answer:

    Reads all items in a table -> Option A
  4. Quick Check:

    Scan = Reads all items [OK]
Hint: Scan reads entire table, not just keys [OK]
Common Mistakes:
  • Confusing scan with get or query
  • Thinking scan deletes or updates data
  • Assuming scan reads only filtered items
2. Which of the following is the correct syntax to perform a scan operation using AWS SDK for JavaScript v3?
easy
A. const data = await client.get({ TableName: 'MyTable' });
B. const data = await client.query({ TableName: 'MyTable' });
C. const data = await client.scan({ TableName: 'MyTable' });
D. const data = await client.delete({ TableName: 'MyTable' });

Solution

  1. Step 1: Identify scan method usage

    The scan method is called on the DynamoDB client with parameters including TableName.
  2. Step 2: Check other methods

    Get, query, and delete are different operations and do not perform scan.
  3. Final Answer:

    const data = await client.scan({ TableName: 'MyTable' }); -> Option C
  4. Quick Check:

    Scan syntax uses client.scan() [OK]
Hint: Scan uses client.scan() with TableName [OK]
Common Mistakes:
  • Using get or query instead of scan
  • Missing await keyword
  • Wrong method names like delete
3. Given a DynamoDB table with 3 items: {id:1, name:'A'}, {id:2, name:'B'}, {id:3, name:'C'}, what will the scan operation return?
medium
A. [{id:1, name:'A'}, {id:2, name:'B'}, {id:3, name:'C'}]
B. Error: No items found
C. []
D. [{id:1, name:'A'}]

Solution

  1. Step 1: Understand scan returns all items

    Scan reads every item in the table, so all 3 items will be returned.
  2. Step 2: Check options for completeness

    Only [{id:1, name:'A'}, {id:2, name:'B'}, {id:3, name:'C'}] lists all 3 items; others are incomplete or errors.
  3. Final Answer:

    [{id:1, name:'A'}, {id:2, name:'B'}, {id:3, name:'C'}] -> Option A
  4. Quick Check:

    Scan returns all items [OK]
Hint: Scan returns full table items list [OK]
Common Mistakes:
  • Expecting scan to return only one item
  • Thinking scan returns empty if no filter
  • Confusing scan with query results
4. You wrote this code to scan a DynamoDB table but get no results:
const params = { TableName: 'MyTable', FilterExpression: 'age > :val', ExpressionAttributeValues: { ':val': 30 } };
const data = await client.scan(params);

What is the likely problem?
medium
A. TableName is missing in params
B. FilterExpression syntax is incorrect, causing scan to fail
C. Scan does not support FilterExpression
D. FilterExpression is applied after scan reads all items, so no items match age > 30

Solution

  1. Step 1: Understand FilterExpression in scan

    FilterExpression filters results after scanning all items; if no items match, result is empty.
  2. Step 2: Check syntax and params

    Syntax is correct, TableName is present, and scan supports FilterExpression.
  3. Final Answer:

    FilterExpression is applied after scan reads all items, so no items match age > 30 -> Option D
  4. Quick Check:

    FilterExpression filters after scan [OK]
Hint: FilterExpression filters after scan reads all items [OK]
Common Mistakes:
  • Thinking FilterExpression prevents scanning items
  • Assuming scan fails with FilterExpression
  • Missing TableName parameter
5. You want to scan a large DynamoDB table but only retrieve items where status is 'active'. Which approach is best to reduce data returned and improve performance?
hard
A. Use scan with FilterExpression 'status = :s' and ExpressionAttributeValues { ':s': 'active' }
B. Use query operation with status as partition key
C. Use scan without filters and filter results in application code
D. Use scan with ProjectionExpression to get only 'status' attribute

Solution

  1. Step 1: Understand scan vs query

    Scan reads entire table; query reads items by key, more efficient for filtering.
  2. Step 2: Check if status can be partition key

    If status is partition key, query can efficiently get only 'active' items without scanning all.
  3. Step 3: Evaluate other options

    FilterExpression filters after scan, so less efficient; filtering in app wastes bandwidth; ProjectionExpression only limits attributes, not items.
  4. Final Answer:

    Use query operation with status as partition key -> Option B
  5. Quick Check:

    Query with key filters efficiently [OK]
Hint: Query by key is faster than scan with filters [OK]
Common Mistakes:
  • Relying on scan with filters for large tables
  • Filtering data in application instead of query
  • Confusing ProjectionExpression with filtering items