0
0
DynamoDBquery~5 mins

Table capacity modes (on-demand vs provisioned) in DynamoDB

Choose your learning style9 modes available
Introduction

Table capacity modes decide how you pay for and handle the speed of your database. They help you manage costs and performance easily.

When you expect unpredictable or spiky traffic to your database.
When you want to control costs by setting a fixed capacity for your database.
When you want your database to automatically adjust to traffic without manual changes.
When you have steady, predictable traffic and want to optimize cost.
When you want to avoid throttling during sudden traffic bursts.
Syntax
DynamoDB
CreateTable {
  TableName: string,
  BillingMode: 'PROVISIONED' | 'PAY_PER_REQUEST',
  ProvisionedThroughput?: {
    ReadCapacityUnits: number,
    WriteCapacityUnits: number
  }
}

BillingMode can be PROVISIONED or PAY_PER_REQUEST (on-demand).

If you choose PROVISIONED, you must specify ProvisionedThroughput.

Examples
This creates a table that charges you based on the requests you make, no need to set capacity.
DynamoDB
CreateTable {
  TableName: 'Users',
  BillingMode: 'PAY_PER_REQUEST'
}
This creates a table with fixed read and write capacity units, good for steady traffic.
DynamoDB
CreateTable {
  TableName: 'Orders',
  BillingMode: 'PROVISIONED',
  ProvisionedThroughput: {
    ReadCapacityUnits: 5,
    WriteCapacityUnits: 5
  }
}
Sample Program

This command creates a DynamoDB table named ExampleTable using the on-demand capacity mode. You don't need to set read or write capacity units.

DynamoDB
aws dynamodb create-table \
  --table-name ExampleTable \
  --attribute-definitions AttributeName=Id,AttributeType=S \
  --key-schema AttributeName=Id,KeyType=HASH \
  --billing-mode PAY_PER_REQUEST
OutputSuccess
Important Notes

On-demand mode is great for unpredictable workloads but can cost more if traffic is steady and high.

Provisioned mode lets you save money with steady traffic but requires you to guess capacity needs.

You can switch between modes later if your needs change.

Summary

Table capacity modes control how you pay and handle traffic in DynamoDB.

On-demand mode charges per request and adjusts automatically.

Provisioned mode requires setting fixed read/write capacity but can save money for steady use.