# DynamoDB at a Glance — AWS Fundamentals: Core Services for Cloud Beginners

Source: https://www.geekswithgeeks.com/en/aws/aws-dynamodb

> Store key-value and document data at any scale with DynamoDB tables, partition and sort keys and on-demand capacity.

## A serverless NoSQL database

**DynamoDB** is a fully managed NoSQL database with single-digit-millisecond reads and writes. You design a table around a **partition key** (and optional **sort key**) and query by those keys. Capacity can be **on-demand** (pay per request) or provisioned.

## Put and query items

Design for your access patterns first: a query by partition key is fast, while a full table scan is slow and costly.

```bash
aws dynamodb put-item --table-name Orders \
  --item '{"customerId":{"S":"c42"},"orderId":{"S":"o1001"},"total":{"N":"499"}}'

aws dynamodb query --table-name Orders \
  --key-condition-expression "customerId = :c" \
  --expression-attribute-values '{":c":{"S":"c42"}}'
```

Choose a partition key with many distinct values so load spreads evenly. Use DynamoDB when access patterns are known; use RDS when you need flexible joins and ad hoc queries.

Quick check

**Quiz:** What does a DynamoDB query use to find items fast?

- [x] The partition key (and sort key)
- [ ] A full table scan
- [ ] SQL joins
- [ ] The AMI id

*Answer:* The partition key (and sort key). Queries by key are fast; scans read the whole table.
