Bird
Raised Fist0
DynamoDBquery~30 mins

Attribute types (S, N, B, BOOL, L, M) in DynamoDB - Mini Project: Build & Apply

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
Working with DynamoDB Attribute Types
📖 Scenario: You are building a simple inventory system using DynamoDB. Each item in the inventory has different types of attributes like strings, numbers, booleans, lists, and maps.
🎯 Goal: Create a DynamoDB item using various attribute types: S (string), N (number), B (binary), BOOL (boolean), L (list), and M (map).
📋 What You'll Learn
Create a DynamoDB item dictionary named item with specific attributes.
Add a configuration variable binary_data to hold binary content.
Use the correct DynamoDB attribute types for each attribute in item.
Complete the item with all required attributes using the correct DynamoDB data types.
💡 Why This Matters
🌍 Real World
DynamoDB is widely used for fast, scalable NoSQL databases in web and mobile applications. Understanding attribute types is essential for storing and retrieving data correctly.
💼 Career
Many cloud and backend developer roles require working with DynamoDB or similar NoSQL databases. Knowing how to structure data with correct attribute types is a key skill.
Progress0 / 4 steps
1
Create the initial DynamoDB item with string and number attributes
Create a dictionary called item with two attributes: "ProductName" as a string with value "Coffee Mug" and "Price" as a number with value 12.99. Use DynamoDB attribute types S for string and N for number.
DynamoDB
Hint

Remember, DynamoDB numbers are stored as strings inside the N attribute.

2
Add a binary attribute configuration
Create a variable called binary_data and assign it the byte string b'\x01\x02\x03' to represent binary data.
DynamoDB
Hint

Use the b'' syntax to create a byte string in Python.

3
Add boolean, binary, list, and map attributes to the item
Add these attributes to the item dictionary: "InStock" as a boolean True using BOOL, "Image" as binary using B with the variable binary_data, "Tags" as a list L containing two strings "Ceramic" and "Kitchen", and "Dimensions" as a map M with keys "Height" and "Width" having number values 4 and 3 respectively.
DynamoDB
Hint

Lists use L with a list of attribute dictionaries. Maps use M with a dictionary of attribute dictionaries.

4
Complete the DynamoDB item with all attributes
Ensure the item dictionary includes all attributes: ProductName (string), Price (number), InStock (boolean), Image (binary), Tags (list of strings), and Dimensions (map with height and width numbers). The variable binary_data should be defined as b'\x01\x02\x03'.
DynamoDB
Hint

Review all attribute types and ensure the dictionary is complete and correctly formatted.

Practice

(1/5)
1.

Which DynamoDB attribute type is used to store plain text strings?

easy
A. B
B. N
C. BOOL
D. S

Solution

  1. Step 1: Understand attribute types in DynamoDB

    DynamoDB uses attribute types to define data kinds. 'S' stands for string (text).
  2. Step 2: Match the type to text data

    Since 'S' means string, it is the correct type for plain text.
  3. Final Answer:

    S -> Option D
  4. Quick Check:

    Text data = S [OK]
Hint: Text data always uses type S in DynamoDB [OK]
Common Mistakes:
  • Confusing N (number) with S (string)
  • Choosing BOOL for text
  • Using B for text data
2.

Which of the following is the correct syntax to define a boolean attribute named isActive in a DynamoDB item?

{"isActive": {"BOOL": true}}
easy
A. {"isActive": {"S": "true"}}
B. {"isActive": {"BOOL": true}}
C. {"isActive": {"N": 1}}
D. {"isActive": {"B": true}}

Solution

  1. Step 1: Identify the correct attribute type for boolean

    Boolean values in DynamoDB use the BOOL type with true or false.
  2. Step 2: Check the syntax for boolean attribute

    The correct syntax is {"isActive": {"BOOL": true}} to represent a boolean true.
  3. Final Answer:

    {"isActive": {"BOOL": true}} -> Option B
  4. Quick Check:

    Boolean attribute uses BOOL type [OK]
Hint: Use BOOL type with true/false for boolean values [OK]
Common Mistakes:
  • Using S type with string 'true'
  • Using N type with 1 instead of BOOL
  • Using B type for boolean
3.

Given the following DynamoDB item attribute, what is the type of tags?

{"tags": {"L": [ {"S": "red"}, {"S": "blue"}, {"S": "green"} ] }}
medium
A. List (L)
B. Map (M)
C. String (S)
D. Binary (B)

Solution

  1. Step 1: Identify the attribute type key

    The attribute uses the key "L", which stands for List in DynamoDB.
  2. Step 2: Understand the value structure

    The value is an array of strings, confirming it is a list of string elements.
  3. Final Answer:

    List (L) -> Option A
  4. Quick Check:

    Attribute key L means List [OK]
Hint: Look for L key to identify lists in DynamoDB [OK]
Common Mistakes:
  • Confusing L with M (map)
  • Thinking it's a string because of S inside list
  • Choosing B for binary data
4.

Identify the error in this DynamoDB attribute definition:

{"profile": {"M": {"age": {"S": 30}, "name": {"S": "Alice"}}}}
medium
A. The name attribute should use type N, not S
B. The map (M) type cannot contain nested attributes
C. The age attribute should use type N, not S
D. Binary (B) type is missing for profile

Solution

  1. Step 1: Analyze the attribute types inside the map

    The map contains "age" with type S and value 30, and "name" with type S and value "Alice".
  2. Step 2: Check if types match values

    Age is a number (30), so it should use type N, not S (string). Name is correctly a string.
  3. Final Answer:

    Age attribute should use type N, not S -> Option C
  4. Quick Check:

    Numbers use N type, not S [OK]
Hint: Numbers inside maps must use N type, not S [OK]
Common Mistakes:
  • Using S for numbers
  • Thinking maps can't nest attributes
  • Confusing name type as number
5.

You want to store a user's profile with a list of phone numbers and a map of address details in DynamoDB. Which attribute types should you use for phoneNumbers and address respectively?

hard
A. phoneNumbers: L, address: M
B. phoneNumbers: M, address: L
C. phoneNumbers: S, address: B
D. phoneNumbers: BOOL, address: N

Solution

  1. Step 1: Identify the type for a list of phone numbers

    A list of phone numbers is a collection, so it should use the List (L) type.
  2. Step 2: Identify the type for address details as key-value pairs

    Address details are structured data with keys and values, so Map (M) type is appropriate.
  3. Final Answer:

    phoneNumbers: L, address: M -> Option A
  4. Quick Check:

    Lists = L, Maps = M [OK]
Hint: Use L for lists, M for maps (objects) in DynamoDB [OK]
Common Mistakes:
  • Swapping L and M types
  • Using S for lists
  • Using BOOL or N incorrectly