0
0
AWScloud~5 mins

DynamoDB capacity modes (on-demand, provisioned) in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
DynamoDB capacity modes control how you pay for and manage the read and write throughput of your database. Choosing the right mode helps you handle traffic efficiently without overspending or running out of capacity.
When you expect unpredictable or spiky traffic and want to pay only for what you use without managing capacity.
When you have steady, predictable traffic and want to save costs by specifying exact read and write capacity.
When you want to avoid throttling by automatically scaling capacity with demand.
When you want to control costs tightly by setting limits on read and write units.
When you want to switch between modes as your application traffic patterns change.
Config File - dynamodb-table.json
dynamodb-table.json
{
  "TableName": "example-table",
  "AttributeDefinitions": [
    {
      "AttributeName": "id",
      "AttributeType": "S"
    }
  ],
  "KeySchema": [
    {
      "AttributeName": "id",
      "KeyType": "HASH"
    }
  ],
  "BillingMode": "PAY_PER_REQUEST"
}

This JSON file defines a DynamoDB table named example-table with a simple primary key id of type string.

The BillingMode is set to PAY_PER_REQUEST, which means the table uses the on-demand capacity mode. DynamoDB will automatically handle capacity and billing based on usage.

To use provisioned mode, you would omit BillingMode and instead specify ProvisionedThroughput with ReadCapacityUnits and WriteCapacityUnits.

Commands
This command creates a DynamoDB table using the JSON file that sets the capacity mode to on-demand. It tells AWS to create the table with automatic capacity management.
Terminal
aws dynamodb create-table --cli-input-json file://dynamodb-table.json
Expected OutputExpected
{ "TableDescription": { "TableName": "example-table", "TableStatus": "CREATING", "BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" }, "KeySchema": [ { "AttributeName": "id", "KeyType": "HASH" } ], "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], "TableArn": "arn:aws:dynamodb:us-east-1:123456789012:table/example-table" } }
--cli-input-json - Specifies the JSON file with table configuration
This command checks the current status and configuration of the DynamoDB table to confirm it was created with the on-demand capacity mode.
Terminal
aws dynamodb describe-table --table-name example-table
Expected OutputExpected
{ "Table": { "TableName": "example-table", "TableStatus": "ACTIVE", "BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" }, "KeySchema": [ { "AttributeName": "id", "KeyType": "HASH" } ], "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ] } }
This command switches the table from on-demand to provisioned capacity mode, setting fixed read and write capacity units to control costs and performance.
Terminal
aws dynamodb update-table --table-name example-table --billing-mode PROVISIONED --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Expected OutputExpected
{ "TableDescription": { "TableName": "example-table", "BillingModeSummary": { "BillingMode": "PROVISIONED" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableStatus": "UPDATING" } }
--billing-mode - Sets the capacity mode to provisioned
--provisioned-throughput - Specifies the fixed read and write capacity units
This command verifies the table's capacity mode and throughput settings after the update to provisioned mode.
Terminal
aws dynamodb describe-table --table-name example-table
Expected OutputExpected
{ "Table": { "TableName": "example-table", "TableStatus": "ACTIVE", "BillingModeSummary": { "BillingMode": "PROVISIONED" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "KeySchema": [ { "AttributeName": "id", "KeyType": "HASH" } ], "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ] } }
Key Concept

If you remember nothing else from this pattern, remember: on-demand mode automatically handles capacity and billing, while provisioned mode requires you to set fixed read and write units to control costs and performance.

Common Mistakes
Trying to set ProvisionedThroughput when BillingMode is PAY_PER_REQUEST
ProvisionedThroughput settings are ignored in on-demand mode and cause errors if specified together.
Use ProvisionedThroughput only when BillingMode is PROVISIONED; omit it for PAY_PER_REQUEST.
Not waiting for the table status to become ACTIVE before updating capacity mode
Updating a table while it is still CREATING or UPDATING can cause errors or delays.
Check table status with describe-table and wait until it is ACTIVE before making changes.
Setting too low provisioned capacity causing throttling
If read or write capacity units are too low for your traffic, requests will be throttled and fail.
Monitor usage and increase provisioned capacity as needed or use on-demand mode for unpredictable traffic.
Summary
Create a DynamoDB table with on-demand capacity by setting BillingMode to PAY_PER_REQUEST in the JSON file.
Use AWS CLI commands to create the table and verify its status and capacity mode.
Switch to provisioned capacity mode by updating the table with fixed read and write capacity units using the update-table command.