Skip to content

Instantly share code, notes, and snippets.

@regiszanandrea
Last active February 4, 2021 10:38
Show Gist options
  • Save regiszanandrea/9d40251c8a45b3052f3861f1160b06cf to your computer and use it in GitHub Desktop.
Save regiszanandrea/9d40251c8a45b3052f3861f1160b06cf to your computer and use it in GitHub Desktop.
DynamoDB 101
Items = rows
Hash Key: Partition Key
Range Key: Sort Key
Primary key:
- Partition key
- Partition key + Sort Key (unique)
LSI (Local Secondary Index): use when partition key is the same of the primary key
GSI (Global Secondary Index): use when partition key is not the same of the primary key
Hot Partition: Frequent access of the same key in a partition
To avoid request throttling, design your DynamoDB table with the right partition key
to meet your access requirements and provide even distribution of data.
Operations:
Scan: read all items of the table
Query: uses indexes to read items
PutItem: Creates a new item, or replaces an old item with a new item
UpdateItem: Edits an existing item's attributes, or adds a new item to the table if it does not already exist
DeleteItem: Deletes a single item in a table by primary key
GetItem: return a set of attributes for the item with the given primary key.
BatchGetItem: return the attributes of one or more items from one or more tables
BatchWriteItem: puts or delete multiple items in one or more tables.
Global Tables:
Can specify the AWS Regions where you want the table to be available.
DynamoDB performs all of the necessary tasks to create identical tables in these Regions and propagate ongoing data
changes to all of them.
Transactions:
Provide ACID in DynamoDB. There is no additional cost to enable transactions for your DynamoDB tables.
use TransactWriteItems or TransactGetItems
Encryption:
at rest: use AWS KMS to encrypt all table data including:
- Primary Key
- LSIs and GSIs
- Streams
- Global Tables
- Backups
- Dax Clusters
in transit: uses HTTPS
TTL (Time to Live)
Let's you define when table items expire. DynamoDB delete the item for you. It's recommended to use a timestamp field
Use cases:
- Session Data
- Event Logs
- Other temporary sensitive data for contractual or regulatory compliance
Streams:
Use when you want to listen a table events.
DAX:
DAX is a DynamoDB-compatible caching service that enables you to benefit from fast in-memory performance for demanding
applications. DAX addresses three core scenarios:
- As an in-memory cache, DAX reduces the response times of eventually consistent read workloads by an order of
magnitude from single-digit milliseconds to microseconds.
- DAX reduces operational and application complexity by providing a managed service that is API-compatible with DynamoDB.
Therefore, it requires only minimal functional changes to use with an existing application.
- For read-heavy or bursty workloads, DAX provides increased throughput and potential operational cost savings by reducing
the need to overprovision read capacity units. This is especially beneficial for applications that require repeated reads
for individual keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment