Learn/Data
Data · 15 min read · August 2026
DynamoDB Foundations: Keys, Capacity, and a Single Table
Partition key, sort key, RCU/WCU, and why AWS documentation pushes access-pattern design before you open the table wizard.
Source. Amazon DynamoDB Developer Guide · Core components · Best practices
Abstract & theoretical context
DynamoDB is a serverless key-value and document store. Every item lives under a partition key; an optional sort key makes a composite primary key. Throughput is provisioned (RCU/WCU) or on-demand. Secondary indexes (GSI/LSI) are extra access paths, not SQL joins. Chapter projects fail when someone models DynamoDB like RDS (third normal form) instead of listing queries first. This note follows the official core-components guide: design the query, then the key, then the item.
Models, formulas & variables
1. Primary key
ItemId = PK or ItemId = (PK, SK)
- — PK determines the partition. Hot partitions come from a low-cardinality PK (e.g. status=ACTIVE).
- — SK enables range queries inside one partition: begins_with, between.
2. Capacity sketch
RCU ≈ 4 KB strongly consistent reads/sec; WCU ≈ 1 KB writes/sec
- — On-demand bills per request. Provisioned is cheaper when load is flat and known.
- — A 8 KB item costs 2 WCU to put.
Reference implementation
Copy into a sandbox account. Pin Region ap-south-1 unless the lab says otherwise.
dynamodb-lab.sh
AWS CLI · bash
aws dynamodb create-table \
--table-name SbgMembers \
--attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S \
--key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--region ap-south-1
aws dynamodb put-item --table-name SbgMembers --item '{"pk":{"S":"CHAPTER#tcet"},"sk":{"S":"MEMBER#pushkar"},"role":{"S":"founder"}}'
aws dynamodb query --table-name SbgMembers \
--key-condition-expression "pk = :p" \
--expression-attribute-values '{":p":{"S":"CHAPTER#tcet"}}'Lab procedure
- 01Write three queries you actually need (list members in a chapter, get one member, list events by date) before creating a table.
- 02Create a PAY_PER_REQUEST table in ap-south-1 with pk/sk as above.
- 03Put two items, query by pk, get-item by pk+sk.
- 04Attempt a scan. Note why production should not start there.
- 05Delete the table. DynamoDB is cheap until forgotten tables linger.
Key insights
- Scan is not Query. Scan reads the table; Query uses the key.
- GSIs have their own keys and their own cost.
- Single-table design is optional for a first lab. Access patterns are not.
Account & lab requirements
IAM dynamodb:* on a sandbox prefix. Stay in ap-south-1.