Primary keys — partition key and sort key
Every item is found by its primary key. Simple key = just a partition key (like a unique id). Composite key = partition key + sort key, which groups related items under one partition and sorts them. Why: a composite key lets you store, say, all orders for one customer together and query them as a range.
A table keyed by userId (partition) + createdAt (sort).
aws dynamodb create-table \
--table-name Orders \
--attribute-definitions \
AttributeName=userId,AttributeType=S \
AttributeName=createdAt,AttributeType=S \
--key-schema \
AttributeName=userId,KeyType=HASH \
AttributeName=createdAt,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST