Understanding Tables, Items and Attributes in Amazon DynamoDB
This lesson introduces the DynamoDB data model and programming model: how DynamoDB differs from a relational database, tables, items and attributes, data types, the core operations, read consistency and the main table settings. The later lessons in this module build on these ideas.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how DynamoDB's schema, query model and access model differ from those of a relational database.
- Describe tables, items, attributes and primary keys, and the limits that apply to them.
- Distinguish the scalar, document and set data types.
- Explain the difference between PutItem and UpdateItem, and identify the operation for a task.
- Choose between eventually consistent and strongly consistent reads.
- Describe the capacity, table class, encryption and backup settings of a table.
How DynamoDB differs from a relational database
Amazon DynamoDB is a fully managed, serverless NoSQL database that stores data as key-value pairs and documents. There are no servers or storage volumes to size: a developer creates a table, and DynamoDB stores its data across three Availability Zones in the Region, scales throughput and storage, and returns most reads and writes in single-digit milliseconds at any table size.
The programming model differs from a relational database in three ways that shape application code. First, DynamoDB has no fixed schema beyond the primary key, so items in the same table can have different attributes. Second, it has no joins, and efficient reads must name a key, so the data model is designed around the queries the application will run, as Designing Partition Keys and Sort Keys from Access Patterns explains. Third, every request is an independent, signed HTTPS call authorised by IAM. There are no connections to open or pool, which is why DynamoDB suits Lambda functions that scale to thousands of concurrent copies. The following table summarises the differences.
| Characteristic | Relational database (Amazon RDS, Aurora) | Amazon DynamoDB |
|---|---|---|
| Schema | Fixed columns defined in advance | Only the primary key is fixed |
| Relationships | Joins between tables | No joins; related data is stored together by key |
| Queries | Any SQL query | Efficient reads by key or index |
| Access | Database connections and SQL | Signed HTTPS API calls authorised by IAM |
| Scaling | Larger instances and read replicas | Automatic, by partitioning data across servers |
Tables, items and attributes
A table is a collection of items, created in one Region. An item is a single record, similar to a row, and can be up to 400 KB. An attribute is a named value within an item, similar to a column but defined per item. Only the attributes that form the primary key must be present in every item; any other attribute can appear in some items and not others, and attributes can be nested in lists and maps up to 32 levels deep.
The following two items belong to the same Orders table:
{"customerId": "C-1042", "orderId": "2026-10-27#9017", "total": 249.99, "status": "PAID",
"items": [{"sku": "KB-01", "qty": 1}], "shipTo": {"city": "Leeds", "postcode": "LS1 4AP"}}
{"customerId": "C-1042", "orderId": "2026-10-29#9033", "total": 18.50, "status": "NEW",
"giftMessage": "Happy birthday"}Both items have the key attributes customerId and orderId. The first has a nested list and map, and only the second has a giftMessage; DynamoDB accepts both without any schema change.
Primary keys
Every table has a primary key, chosen when the table is created and never changed afterwards. A simple primary key is a partition key alone, such as userId, and each value identifies one item. A composite primary key adds a sort key, such as orderId in the example above, so many items can share a partition key and are stored together in sort key order. DynamoDB hashes the partition key to decide which partition stores an item, so the key determines both how data is spread and which reads are efficient. Key attributes must be of type String, Number or Binary. Designing Partition Keys and Sort Keys from Access Patterns explains how to choose them.
Data types
DynamoDB supports three groups of data types. Each group is described below and summarised in a table.
Scalar types
A scalar holds one value: String, Number, Binary, Boolean or Null. Numbers can have up to 38 digits of precision, and DynamoDB sends them as strings in its API so that no precision is lost between languages. Binary values are sent Base64-encoded. Strings and binary values can be empty unless the attribute is part of a key.
Document types
A List is an ordered collection of values of any type, and a Map is an unordered set of named values, similar to a JSON object. Documents let one item hold structured data, such as the line items and shipping address of an order, and update expressions can change a single nested element, such as shipTo.city, without rewriting the rest.
Set types
A set holds unique values of one scalar type: a String Set, a Number Set or a Binary Set. Sets are unordered, cannot be empty and cannot contain duplicates, so they suit collections such as tags, where adding a value that is already present has no effect.
The low-level API marks each value with a type descriptor, such as {"S": "PAID"}; Working with DynamoDB Expressions, Errors and Local Tools in the SDKs explains how higher-level SDK clients hide these descriptors. The following table summarises the types and their descriptors.
| Group | Type and descriptor | Example value |
|---|---|---|
| Scalar | String (S), Number (N), Binary (B), Boolean (BOOL), Null (NULL) | "PAID", 249.99, true |
| Document | List (L), Map (M) | [1, "a"], {"city": "Leeds"} |
| Set | String Set (SS), Number Set (NS), Binary Set (BS) | {"red", "blue"} |
Core operations
Application code works with DynamoDB through a small set of operations, grouped below by how many items they touch.
Single-item operations
PutItem writes a whole item. If an item with the same primary key exists, it is replaced entirely, so any attribute missing from the new item is lost. GetItem reads one item by its full primary key, the most efficient read in DynamoDB. UpdateItem changes, adds or removes individual attributes, and creates the item if it does not exist. DeleteItem removes an item by its key. All four accept a condition expression, which makes the write succeed only if the item is in an expected state.
Multi-item operations
Query reads the items that share one partition key, optionally filtered by the sort key, and Scan reads every item in a table. BatchGetItem and BatchWriteItem group many single-item requests into one call, and TransactWriteItems and TransactGetItems succeed or fail as a whole. Reading and Writing Items with Queries, Batches, Conditions and Transactions explains each in depth. The following table summarises the operations.
| Operation | Reads or writes | Remember |
|---|---|---|
PutItem | One whole item | Replaces an existing item completely |
GetItem | One item by full primary key | The cheapest, fastest read |
UpdateItem | Selected attributes of one item | Leaves other attributes unchanged |
DeleteItem | One item by key | Can be conditional |
Query / Scan | Many items | Query needs a partition key; Scan reads everything |
| Batch and transaction operations | Many items in one call | Transactions are all-or-nothing |
DynamoDB operations
Read consistency
DynamoDB acknowledges a write once it is durably stored, and then copies it to the other replicas, usually within a second. Reads can choose between two consistency models.
An eventually consistent read is the default. It may be served by a replica that has not yet received the latest write, so a read made immediately after a write can occasionally return the previous value. A strongly consistent read, requested with ConsistentRead=True, always reflects every write that succeeded before it. Strongly consistent reads are available for GetItem, Query and Scan on tables and local secondary indexes, but not on global secondary indexes, and they consume twice as much read capacity, as Choosing a Capacity Mode and Calculating Read and Write Capacity Units explains.
The choice follows from the requirement. A product catalogue can tolerate a value that is a second old, while reading a balance immediately after updating it needs a strongly consistent read.
Items, keys and consistency
Table settings
Beyond the primary key, a table has several settings that affect cost, protection and availability. Each is described below.
- Capacity mode: on-demand, which bills per request and scales automatically, or provisioned, which bills for a set read and write capacity, as the capacity lesson explains.
- Table class: Standard, or Standard-Infrequent Access, which lowers storage cost and raises request cost for tables whose data is rarely read.
- Encryption at rest: always on, with an AWS owned key by default, or an AWS managed or customer managed AWS KMS key for control and auditing.
- Point-in-time recovery: continuous backups that restore the table to any second in the recovery period, of up to 35 days.
- Deletion protection: prevents the table from being deleted until the setting is turned off.
- Global tables: replicate the table to other Regions, where each replica accepts reads and writes.
The following AWS CLI command creates the Orders table with a composite key, on-demand capacity and deletion protection. Only the key attributes are declared; every other attribute is added by the items themselves.
aws dynamodb create-table --table-name Orders \
--attribute-definitions AttributeName=customerId,AttributeType=S AttributeName=orderId,AttributeType=S \
--key-schema AttributeName=customerId,KeyType=HASH AttributeName=orderId,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST --deletion-protection-enabledAttributes that disappear after an update
An order service marks an order as shipped with the following code. After it runs, the order still has its key and its new status, but its total, items and shipTo attributes have gone.
table.put_item(Item={"customerId": "C-1042", "orderId": "2026-10-27#9017", "status": "SHIPPED"})PutItem replaces the whole item with the one supplied, so every attribute not in the request is removed. Changing one attribute needs UpdateItem with an update expression, which leaves the other attributes as they are. Adding a condition also stops the call from creating a new item if the order does not exist:
table.update_item(
Key={"customerId": "C-1042", "orderId": "2026-10-27#9017"},
UpdateExpression="SET #s = :shipped",
ConditionExpression="attribute_exists(orderId)",
ExpressionAttributeNames={"#s": "status"}, # status is a reserved word
ExpressionAttributeValues={":shipped": "SHIPPED"},
)A GetItem call made immediately after a successful UpdateItem sometimes returns the old value. Why, and how can the application always read the new value?
Show answer
Reads are eventually consistent by default, so a read may reach a replica that has not yet received the write. Setting ConsistentRead=True on the GetItem makes it strongly consistent, at twice the read capacity cost.
Exam Tips
Remember for the exam
- DynamoDB is schemaless apart from the primary key, has no joins and is accessed through IAM-authorised HTTPS calls, so it needs no connection pooling from Lambda.
- Items are at most 400 KB; key attributes must be String, Number or Binary, and the primary key cannot be changed after the table is created.
- Sets are unordered, unique and cannot be empty; numbers are sent as strings in the low-level API to preserve precision.
PutItemreplaces the whole item, whileUpdateItemchanges only the attributes in its update expression.GetItemwith the full primary key is the most efficient read; a frequentScanusually signals a missing key or index.- Reads are eventually consistent by default;
ConsistentRead=Truegives strong consistency on tables and LSIs, not GSIs, at twice the read cost. - Encryption at rest is always on; choose a customer managed KMS key when key control or auditing is required, and enable point-in-time recovery for restores.