AWS DynamoDB Pay-Per-Request Billing Mode And On-Demand Read / Write Capacity Mode Configuration
Learn how to configure AWS DynamoDB(DDB) to use pay-per-request billing mode and on-demand read/write capacity mode.
Why On-Demand Read/Write Capacity ModePermalink
Before On-Demand Capacity ModePermalink
Before on-demand capacity mode was introduced, you had to specify provisioned read/write capacity units and the minimum value was 1 unit. However, there are times where usage is less than 1 unit but you are still charged for the provisioned capacity if you are not eligible for free tier. This can happen especially in the process of development and with tables that are used occassionally or unpredictable workloads.
Updated as of 2019 Sep 1st, the following screenshot shows the default capacity mode configuration when a DDB table is created. A DDB table default configuration is to have 5 read and 5 write capacity units. The estimated cost per month for a table is $2.91 for US East region.
With On-Demand Capacity ModePermalink
With on-demand capacity mode, AWS charges you based on the amount of requests you use with your DDB tables.
Updated as of 2019 Sep 1st, the following screenshot shows the price for AWS DDB on-demand read & write requests and data storage price for US East region. It is $1.25 per million write request units and $0.25 per million read request units. Data storage is free for the first 25 GB and $0.25 per GB-month thereafter.
According to AWS DynamoDB documentation, DDB hardware and software are able to scale up and down to accomodate and respond to your DDB tables workloads.
Quote from AWS DynamoDB Pricing page. Check out DDB pricing page for more detailed information.
With on-demand capacity mode, DynamoDB charges you for the data reads and writes your application performs on your tables. You do not need to specify how much read and write throughput you expect your application to perform because DynamoDB instantly accommodates your workloads as they ramp up or down.
After you configure your DDB table to use on-demand read/write capacity mode, your billing-mode for that particular DDB table would be pay-per-request.
What’s in AWS DynamoDB Free Tier BenefitsPermalink
AWS provides a free tier to let users get free, hands-on experience with AWS services. As of 2019 Sep 1st, the following items are included in AWS DynamoDB Free Tier monthly benefits on a per-region, per-payer account basis.
1) 25 WCUs and 25 RCUs of provisioned capacity
2) 25 GB of data storage
3) 25 rWCUs for global tables deployed in two AWS Regions
4) 2.5 million stream read requests from DynamoDB Streams
5) 1 GB of data transfer out (15 GB for your first 12 months),
aggregated across AWS services
- WCU is write capacity unit.
- RCU is read capacity unit.
- rWCU is replicated write capacity unit.
Configure For On-Demand Capacity ModePermalink
There are multiple ways to configure your AWS DDB tables to use pay-per-request billing mode and on-demand capacity mode.
AWS ConsolePermalink
You can do it on AWS DynamoDB console.
- Go to AWS Console and open up your DynamoDB table.
- Open
Capacity
Tab and look forRead/write capacity mode
. - Change Provisioned to
On-demand
if it is not already so. - Wait for a couple minutes for on-demand configuration to take effect.
AWS CLIPermalink
You can set a DDB table to use on-demand read/write capacity mode and pay-per-request billing mode when it is created. You can also modify existing DDB tables.
When you create a new table using create-table command, you can specify its billing-mode
attribute as PAY_PER_REQUEST
.
create-table command
aws dynamodb create-table \
--table-name My-Table \
--attribute-definitions '[
{
"AttributeName": "Id",
"AttributeType": "S"
},
]' \
--key-schema '[
{
"AttributeName": "Id",
"KeyType": "HASH"
},
]' \
--billing-mode: "PAY_PER_REQUEST"
With existing tables, you can update them using update-table command and specify its billing-mode
attribute as PAY_PER_REQUEST
.
update-table command
$ aws dynamodb update-table \
--table-name My-Table \
--billing-mode: "PAY_PER_REQUEST"
AWS CloudFormation in YamlPermalink
You can also configure your DDB tables to use pay-per-request billing mode using AWS CloudFormation AWS::DynamoDB::Table
resource type declaration.
CommUserTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
BillingMode: "PAY_PER_REQUEST"
Support JunPermalink
Thank you for reading! Support Jun
If you are preparing for Software Engineer interviews, I suggest Elements of Programming Interviews in Java for algorithm practice. Good luck!
You can also support me by following me on Medium or Twitter.
Feel free to contact me if you have any questions.
Comments