CDK Constructs for AWS DynamoDB
Project description
Amazon DynamoDB Construct Library
---Here is a minimal deployable DynamoDB table definition:
# Example may have issues. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_dynamodb as dynamodb
table = dynamodb.Table(self, "Table",
partition_key=Attribute(name="id", type=dynamodb.AttributeType.STRING)
)
Keys
When a table is defined, you must define it's schema using the partitionKey
(required) and sortKey
(optional) properties.
Billing Mode
DynamoDB supports two billing modes:
- PROVISIONED - the default mode where the table and global secondary indexes have configured read and write capacity.
- PAY_PER_REQUEST - on-demand pricing and scaling. You only pay for what you use and there is no read and write capacity for the table or its global secondary indexes.
# Example may have issues. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_dynamodb as dynamodb
table = dynamodb.Table(self, "Table",
partition_key=Attribute(name="id", type=dynamodb.AttributeType.STRING),
billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST
)
Further reading: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.
Configure AutoScaling for your table
You can have DynamoDB automatically raise and lower the read and write capacities of your table by setting up autoscaling. You can use this to either keep your tables at a desired utilization level, or by scaling up and down at preconfigured times of the day:
Auto-scaling is only relevant for tables with the billing mode, PROVISIONED.
# Example may have issues. See https://github.com/aws/jsii/issues/826
read_scaling = table.auto_scale_read_capacity(min_capacity=1, max_capacity=50)
read_scaling.scale_on_utilization(
target_utilization_percent=50
)
read_scaling.scale_on_schedule("ScaleUpInTheMorning",
schedule=appscaling.Schedule.cron(hour="8", minute="0"),
min_capacity=20
)
read_scaling.scale_on_schedule("ScaleDownAtNight",
schedule=appscaling.Schedule.cron(hour="20", minute="0"),
max_capacity=20
)
Further reading: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AutoScaling.html https://aws.amazon.com/blogs/database/how-to-use-aws-cloudformation-to-configure-auto-scaling-for-amazon-dynamodb-tables-and-indexes/
Amazon DynamoDB Global Tables
Please see the @aws-cdk/aws-dynamodb-global
package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aws-cdk.aws-dynamodb-1.16.3.tar.gz
.
File metadata
- Download URL: aws-cdk.aws-dynamodb-1.16.3.tar.gz
- Upload date:
- Size: 99.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37cf2a04b7363f84e7a42d6d260c59b20a2b5566a842ae50dd8354cd21ee8e4b |
|
MD5 | 6304b50e9c7f09f70572f6d37ccff37b |
|
BLAKE2b-256 | ed6185e7e1c603d2613c39b9b36624a676ebaffee1ab94f6e68eb9ff7a264c8e |
File details
Details for the file aws_cdk.aws_dynamodb-1.16.3-py3-none-any.whl
.
File metadata
- Download URL: aws_cdk.aws_dynamodb-1.16.3-py3-none-any.whl
- Upload date:
- Size: 98.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a55f586c63a68d18258f474e207036e55930d900774ac599ecbf22d1bc2c57b |
|
MD5 | 71c1e0f7641983129660fb58ae0ff1c9 |
|
BLAKE2b-256 | 36b1e2ffffc4f7f8f43e831b25b008f56398e834f3bf0855235b85f831886eff |