Hands-On: Create a Table

Create the NoteSnap table from the CLI using on-demand billing.

1 min read

You only declare the key attributes when creating a table. Every other attribute is added freely when you write items.

Try it

Terminal
aws dynamodb create-table \
  --table-name notesnap-summaries \
  --attribute-definitions AttributeName=noteId,AttributeType=S \
  --key-schema AttributeName=noteId,KeyType=HASH \
  --billing-mode PAY_PER_REQUEST

# Wait until it's ready
aws dynamodb wait table-exists --table-name notesnap-summaries

Decoding the flags

  • AttributeType=S: String. (N = number, B = binary.)
  • KeyType=HASH: this is the partition key. A sort key would be KeyType=RANGE.
  • PAY_PER_REQUEST: on-demand billing. You pay per read and write, and it scales automatically.

On-demand vs. provisioned

ModeHow it worksChoose it when
On-demandPay per request, scales instantlyNew apps, spiky or unpredictable traffic
ProvisionedReserve read/write capacity per second (with optional auto scaling)Steady, predictable traffic where you want the lowest cost

Key takeaways

  • Only key attributes are declared up front. Everything else is flexible.
  • HASH = partition key, RANGE = sort key.
  • Start with on-demand billing, and switch to provisioned when traffic is steady and predictable.

Check your understanding

Pick an answer to see the explanation.

  1. 1. In the CLI, what does KeyType=RANGE mean?