How do I change the read and write capacity mode for my DynamoDB table?

Lecture de 3 minute(s)
0

I want to change the capacity mode of my Amazon DynamoDB table.

Short description

When you create a DynamoDB table, you must specify either provisioned capacity mode or on-demand capacity mode.

To change the capacity mode of an existing table, use one of the following methods:

  • DynamoDB console
  • AWS Command Line Interface (AWS CLI)
  • Python

Before you switch your capacity mode, see Considerations when switching capacity modes.

Resolution

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

DynamoDB console

Complete the following steps:

  1. Open the DynamoDB console.
  2. In the navigation pane, choose Tables.
  3. Select the table that you want to modify.
  4. Choose Update.
  5. Under Capacity mode, select the new capacity mode that you want to use:
    For Provisioned, enter the read and write capacity units.
    For On-Demand, DynamoDB automatically scales the provisioned capacity up and down based on your application's needs.
  6. Choose Update table.

AWS CLI

To switch the capacity mode of an existing DynamoDB table to Provisioned, run the following command:

aws dynamodb update-table --table-name <YOUR_TABLE_NAME> --billing-mode PROVISIONED --provisioned-throughput ReadCapacityUnits=<YOUR_READ_CAPACITY>,WriteCapacityUnits=<YOUR_WRITE_CAPACITY>

To switch the capacity mode of an existing DynamoDB table to On-demand, run the following command:

aws dynamodb update-table --table-name <YOUR_TABLE_NAME> --billing-mode PAY_PER_REQUEST

Python

You can use an Amazon Elastic Compute Cloud (EC2) instance or AWS Lambda to run a Python script. To switch the capacity mode of an existing DynamoDB table to Provisioned, run the following command:

import boto3

# Create a DynamoDB client
dynamodb = boto3.client('dynamodb', region_name=region_name, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

# Name of your DynamoDB table
table_name = 'YOUR_TABLE_NAME'

# Change the capacity mode to PROVISIONED
response = dynamodb.update_table(
 TableName=table_name,
 BillingMode='PROVISIONED',
 ProvisionedThroughput={
 'ReadCapacityUnits': 5, # Set your desired read capacity units
 'WriteCapacityUnits': 5 # Set your desired write capacity units
 }
)

print("Capacity mode changed to PROVISIONED")

To switch the capacity mode of an existing DynamoDB table to On-demand, run the following command:

import boto3

# Create a DynamoDB client
dynamodb = boto3.client('dynamodb', region_name=region_name, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

# Name of your DynamoDB table
table_name = 'YOUR_TABLE_NAME'

# Change the capacity mode to PAY_PER_REQUEST
response = dynamodb.update_table(
TableName=table_name,
BillingMode='PAY_PER_REQUEST'
)

print("Capacity mode changed to PAY_PER_REQUEST")

Related information

DynamoDB throughput capacity

AWS OFFICIEL
AWS OFFICIELA mis à jour il y a 2 mois