AWS DynamoDB
Amazon DynamoDB is a fully managed NoSQL database for applications that need consistent, single-digit millisecond performance at any scale. There are no servers, patches or clusters to manage, and data is automatically replicated across three Availability Zones of a Region.
Key concepts #
- Table, item (a row) and attributes. Items in the same table can have different attributes.
- Primary key: a partition key, or a partition key plus a sort key. The partition key decides where the item is stored, so a good key spreads the load evenly.
- Secondary indexes: global (GSI) and local (LSI) indexes to query by other attributes.
- Capacity modes: on-demand (pay per request, no planning) or provisioned with Auto Scaling (read and write capacity units).
- Consistency: eventually consistent reads by default, strongly consistent reads optionally, and ACID transactions.
- Global tables replicate a table across Regions with multi-active writes.
- Streams deliver the item changes to Lambda or other consumers; TTL deletes expired items automatically; point-in-time recovery and on-demand backups protect the data; DAX is an in-memory cache.
- Data is encrypted at rest with KMS.
- Access is through the API (not SQL connections), controlled with IAM.
Pricing #
On-demand: per read and write request. Provisioned: per capacity unit per hour. Plus storage and optional features such as global tables, backups and streams. See the DynamoDB pricing.
With Terraform #
The resource is aws_dynamodb_table (also aws_dynamodb_table_item and aws_appautoscaling_target for scaling). DynamoDB was also the traditional way to lock the Terraform state stored in S3, with a table whose key is LockID.
See tutorials:
See also: AWS RDS and AWS Aurora for relational databases, AWS ElastiCache.