Amazon DynamoDB is a NoSQL key-value datastore with support for JSON documents.
It can deliver single-digit millisecond performance at large scale.
DynamoDB is serverless and fully managed. It's easy to set up, operate and scale. You don't have to worry about
capacity scaling, hardware & VM provisioning, database setup, patching and more.
It's multi-active, replicated across multiple Availability Zones, durable and secure. It also supports in-memory
caching.
DynamoDB doesn't have it's own query language. Instead, you can use aws-sdk to access the database.
When to use
Advantages
Performance at scale - DynamoDB supports some of the world’s largest scale applications by providing consistent,
single-digit millisecond response times at any scale. You can build applications with virtually unlimited throughput
and storage.
Auto-scalable - DynamoDb has a support for auto-scaling of both read/write capacity and storage.
IAM access - You can manage the access to your DynamoDb database with AWS Identity and Access management rules.
Connection-less - You don't have to worry about connection pool exhaustions.
Serverless - DynamoDb supports "pay-as-you-go" pricing. If there's no database load, it's essentially free.
Disadvantages
Relatively unmature - Not as mature as relational (SQL) databases. It has a signficantly less rich ecosystem.
Proprietary - DynamoDb is a properitary AWS database.
Not feature rich - DynamoDb is more of a data-store, not a fully-featured database such as Postgres or MongoDb.
For a detailed comparison (even tho arguably slightly biased), refer to
MongoDb comparsion.
In a table that has only partitionKey and no sortKey, no two items can have the same partitionKey.
Internally, DynamoDB uses the partitionKey's value as an input to an internal hash function. The output from
the hash function determines the partition (physical location) where the item is stored.
sortKey
If specified, this attribute becomes part of the composite primary key together with partitionKey
Using a sortKey in the primary key gives you additional flexibility when querying data.
In a table that has a partitionKey and a sortKey, it's possible for two items to have the
same partitionKey value. However, those two items must have different sortKey values.
All items with the same partitionKey are stored together in the same partion in sorted
order by sortKey value.
The above applies for an item of up to 4 KB in size. If you need to read an item that is
larger than 4 KB, additional read capacity units are consumed.
writeUnits
Required
Number of write units available every second
Type: number
One write unit represents one write per second for an item of up to 1 KB in size.
If exceeded, you receive a ThrottlingException.
If you need to write an item that is larger than 1 KB, additional write capacity units are consumed.
Even in provisioned mode, you can configure throughput scaling based on load.
The table throughput scales up or down once the specified thresholds are met.
Compared to on-demand mode (default, if you don't specify provisionedThroughput), you have more control
of how your table will scale and can save costs. However, your table might not be able to scale enough for an unpredictable load.
Even in provisioned mode, you can configure throughput scaling based on load.
The table throughput scales up or down once the specified thresholds are met.
Compared to on-demand mode (default, if you don't specify provisionedThroughput), you have more control
of how your table will scale and can save costs. However, your table might not be able to scale enough for an unpredictable load.
Even in provisioned mode, you can configure throughput scaling based on load.
The table throughput scales up or down once the specified thresholds are met.
Compared to on-demand mode (default, if you don't specify provisionedThroughput), you have more control
of how your table will scale and can save costs. However, your table might not be able to scale enough for an unpredictable load.
Minimum number of provisioned read units (per second) available.
Type: number
Available read units will never scale down below this threshold
maxUnits
Required
Maximum number of provisioned read units (per second) table can scale up to
Type: number
Available read units will never scale up above the defined threshold
keepUtilizationUnder
Required
Percentual utilization threshold for scaling
Type: number
If the table's consumed read capacity exceeds your target utilization (or falls below the target)
for a sustained amount of time, the provisioned capacity is increased (decreased).
Minimum number of provisioned write units (per second) available
Type: number
Available write units will never scale down below this threshold
maxUnits
Required
Maximum number of provisioned write units (per second) table can scale up to
Type: number
Available write units will never scale up above the defined threshold
keepUtilizationUnder
Required
Percentual utilization threshold for scaling
Type: number
If the table's consumed write capacity exceeds your target utilization (or falls below the target)
for a sustained amount of time, the provisioned capacity is increased (decreased).
Point-in-time recovery
No description
resources:
myDynamoDbTable:
type: dynamo-db-table
properties:
primaryKey:
partitionKey:
name: this_attribute_will_be_id
type: string
enablePointInTimeRecovery:true
Item-change streaming
DynamoDb allows yout to stream item-level modifications in the table.
You must configure stream type. It determines what information is written to the stream for this table when the item
in the table is modified. Allowed values are:
KEYS_ONLY - Only the key attributes of the modified item are written to the stream.
NEW_IMAGE - The entire item, as it appears after it was modified, is written to the stream.
OLD_IMAGE - The entire item, as it appeared before it was modified, is written to the stream.
NEW_AND_OLD_IMAGES - Both the new and the old item images of the item are written to the stream.
resources:
myDynamoDbTable:
type: dynamo-db-table
properties:
primaryKey:
partitionKey:
name: this_attribute_will_be_id
type: string
streamType: NEW_AND_OLD_IMAGES
Access control
DynamoDb uses AWS IAM (Identity and Access Management) to control who can access the table.
To interact with the DynamoDb table, your resources must have the sufficient permissions. You can give these
permissions in 2 ways: