Amazon DynamoDB is a fully managed NoSQL database. There are no servers to run, it is built for fast reads and writes at any size, and you design your tables around how your app asks for data. After a relational database like RDS, it is the next database worth understanding.
What it does
- Stores data as items (like rows) in tables, and each item is a set of attributes.
- Finds items quickly by their key.
- Scales without you managing servers.
- Can be billed on demand or with provisioned capacity.
Key concepts
| Piece | What it is |
|---|---|
| Table | A collection of items |
| Partition key | The main key, used to find and spread items |
| Sort key | An optional second key that orders items with the same partition key |
| Item and attribute | One record and its fields, with no fixed schema except the key |
| Secondary index | A way to query by another key (global or local) |
| On-demand and provisioned | Pay per request, or set read and write capacity |
| TTL | Automatically expires items after a time you set |
Good to know
- Design the table from your access patterns: first decide what questions the app asks.
- Choose a partition key with many different values so traffic is spread evenly.
- Use a query with the key when you can. A scan reads the whole table and is slower and costs more.
- On-demand mode is the simplest way to start, and you can check the current pricing before you choose.
- Add a secondary index only when you need a second way to look up items.
- Use TTL for data that should expire, such as sessions.
- DynamoDB is not a relational database, so it has no joins. Use RDS if you need joins and complex queries.
- Turn on point-in-time recovery if you need to restore the table.
Hands-on: try it in your own account
- Open DynamoDB > Tables and choose Create table.
- Name it
Orders, set the partition key tocustomerId(String) and the sort key toorderId(String). - Choose on-demand capacity and create the table.
- Open Explore items and create a few items with different
customerIdvalues. - Run a query for one
customerIdand see all of that customer's orders. - Run a scan and compare it with the query.
- Optional: turn on TTL with an attribute such as
expiresAt. - Clean up: delete the table.
Common mistakes
- Using a partition key with only a few values, so one partition gets all the traffic.
- Using scans for everyday lookups.
- Designing tables like relational tables with joins in mind.
- Not checking the pricing and leaving a provisioned table running with too much capacity.
- Forgetting to delete the practice table.
Key takeaways
- DynamoDB is a managed NoSQL database that finds items by key.
- Design around your access patterns.
- Choose a partition key with many values, and use query instead of scan.
- Delete the practice table when you are done.
Tomorrow I'll start a new AWS topic.
Part of #120DaysOfAWS.

