Labs ICT
Pro Login

DynamoDB Introduction

What is DynamoDB?

DynamoDB is AWS's fully managed NoSQL database. Unlike traditional databases that use tables with rows and columns, DynamoDB uses a key-value and document model. It's fast, scalable, and requires zero administration.

Think of it as a massive, super-fast spreadsheet where you can look up data instantly by its primary key. No need to worry about indexes, query optimization, or database tuning — DynamoDB handles all of that.

How DynamoDB Differs from RDS

RDS is great for structured data with relationships — like a customer database where orders reference customers. DynamoDB shines when you need to store and retrieve data fast, especially at massive scale.

DynamoDB doesn't support joins or complex queries like SQL databases do. Instead, you design your tables around your access patterns. If you know exactly how you'll query your data, DynamoDB can return results in single-digit milliseconds, even at millions of requests per second.

Primary Keys

Every DynamoDB item needs a primary key. A simple primary key has just a partition key — think of it as a unique ID. A composite primary key has a partition key plus a sort key, which lets you sort items within the same partition.

Choosing the right primary key is crucial. It determines how efficiently you can retrieve data. A good rule of thumb: design your keys based on your most frequent access patterns.

Reading and Writing Data

DynamoDB operations are simple: PutItem creates or replaces an item, GetItem retrieves one by key, Query finds items by key conditions, and Scan reads every item (slow, avoid it).

aws dynamodb put-item \
  --table-name Users \
  --item '{"id": {"S": "user123"}, "name": {"S": "Alice"}}'

aws dynamodb get-item \
  --table-name Users \
  --key '{"id": {"S": "user123"}}'

Notice the type annotations like {"S": "value"} — DynamoDB requires explicit data types. S means String, N means Number, B means Binary.

Capacity Modes

On-Demand mode charges per read/write request. Perfect for unpredictable workloads — you pay for what you use, no capacity planning needed.

Provisioned mode lets you set a fixed capacity level (reads and writes per second). You pay for the provisioned capacity whether you use it or not, but it's cheaper if your usage is consistent. You can also enable auto-scaling to adjust capacity automatically.