0
0
DynamoDBquery~10 mins

Attribute types (S, N, B, BOOL, L, M) in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Attribute types (S, N, B, BOOL, L, M)
Start with attribute
Check attribute type
S
Store as string
Store as number
Store as binary
Store as boolean
Store as list
Store as map
Reject invalid type
The attribute type is checked and stored accordingly: string (S), number (N), binary (B), boolean (BOOL), list (L), or map (M). Invalid types are rejected.
Execution Sample
DynamoDB
Item = {
  "Name": {"S": "Alice"},
  "Age": {"N": "30"},
  "IsMember": {"BOOL": true},
  "Tags": {"L": [{"S": "VIP"}, {"S": "Premium"}]},
  "Details": {"M": {"Height": {"N": "170"}}}
}
This code defines a DynamoDB item with attributes of different types: string, number, boolean, list, and map.
Execution Table
StepAttributeType DetectedActionStored Format
1NameSStore as string{"S": "Alice"}
2AgeNStore as number{"N": "30"}
3IsMemberBOOLStore as boolean{"BOOL": true}
4TagsLStore as list{"L": [{"S": "VIP"}, {"S": "Premium"}]}
5DetailsMStore as map{"M": {"Height": {"N": "170"}}}
6UnknownAttrXReject invalid typeError: Invalid attribute type
💡 All attributes processed; invalid type rejected at step 6.
Variable Tracker
AttributeInitialAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6
Nameundefined{"S": "Alice"}{"S": "Alice"}{"S": "Alice"}{"S": "Alice"}{"S": "Alice"}{"S": "Alice"}
Ageundefinedundefined{"N": "30"}{"N": "30"}{"N": "30"}{"N": "30"}{"N": "30"}
IsMemberundefinedundefinedundefined{"BOOL": true}{"BOOL": true}{"BOOL": true}{"BOOL": true}
Tagsundefinedundefinedundefinedundefined{"L": [{"S": "VIP"}, {"S": "Premium"}]}{"L": [{"S": "VIP"}, {"S": "Premium"}]}{"L": [{"S": "VIP"}, {"S": "Premium"}]}
Detailsundefinedundefinedundefinedundefinedundefined{"M": {"Height": {"N": "170"}}}{"M": {"Height": {"N": "170"}}}
UnknownAttrundefinedundefinedundefinedundefinedundefinedundefinedError: Invalid attribute type
Key Moments - 3 Insights
Why is the number attribute stored as a string in the 'N' type?
In DynamoDB, numbers are stored as strings to preserve precision and avoid floating-point errors, as shown in execution_table step 2.
What happens if an attribute type is not one of S, N, B, BOOL, L, or M?
The attribute is rejected as invalid, demonstrated in execution_table step 6 where 'UnknownAttr' causes an error.
How are complex data structures like lists and maps stored?
Lists (L) store ordered collections of attributes, and maps (M) store key-value pairs of attributes, as seen in steps 4 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. What is the stored format of the 'IsMember' attribute?
A{"BOOL": true}
B{"S": "true"}
C{"N": "1"}
Dtrue
💡 Hint
Check the 'Stored Format' column for step 3 in the execution_table.
At which step does the process reject an invalid attribute type?
AStep 2
BStep 4
CStep 6
DStep 5
💡 Hint
Look for the row with 'Reject invalid type' in the 'Action' column.
If the 'Age' attribute was given as {"N": 30} (number, not string), how would the execution_table change?
AStep 2 would store as string with value "30"
BStep 2 would show an error for invalid type
CStep 2 would store as number with value 30
DNo change; DynamoDB accepts number type directly
💡 Hint
DynamoDB requires numbers as strings; see step 2 where number is stored as string.
Concept Snapshot
DynamoDB attribute types:
- S: String stored as string
- N: Number stored as string
- B: Binary data
- BOOL: Boolean true/false
- L: List of attributes
- M: Map (key-value pairs)
Invalid types cause errors.
Numbers must be strings to keep precision.
Full Transcript
This visual execution shows how DynamoDB processes attribute types. Each attribute is checked for its type: string (S), number (N), binary (B), boolean (BOOL), list (L), or map (M). The attribute is then stored in the corresponding format. Numbers are stored as strings to avoid precision loss. Lists and maps allow complex nested data. If an attribute type is invalid, it is rejected with an error. The execution table traces each attribute step by step, showing the stored format and actions taken. Variable tracking shows how each attribute's value is set after each step. Key moments clarify common confusions about number storage, invalid types, and complex structures. The quiz tests understanding of stored formats, error detection, and type requirements. The snapshot summarizes the attribute types and key rules for DynamoDB.