zfn9
Published on July 16, 2025

Guide to Creating and Managing DynamoDB Tables via AWS CLI

Introduction

Working with cloud databases often feels faster when you can skip the browser and get straight to the point. AWS DynamoDB is a fully managed NoSQL service known for its simplicity and scalability. Managing it through the web console can sometimes feel clunky, especially for repetitive tasks. That’s where the AWS Command Line Interface (CLI) comes in handy.

With just a few commands, you can create, update, monitor, and delete DynamoDB tables directly from your terminal. It’s scriptable, reliable, and easy to integrate into automated workflows. This guide provides clear, practical steps to create and manage DynamoDB tables using AWS CLI, without unnecessary complexity.

Setting Up AWS CLI

Before working with DynamoDB from the command line, you’ll need to set up the AWS CLI on your machine. Download the installer from AWS and follow the simple steps to get started. To connect it to your account, run:

aws configure

You’ll be asked for your access key, secret key, default region, and preferred output format. This configuration tells the CLI which account and region to work with. Ensure the IAM user or role you’re using has permission to work with DynamoDB. Once configured, you’re ready to create and manage tables easily.

Creating a DynamoDB Table

After setting up AWS CLI, creating a DynamoDB table is straightforward. The command is short, but understanding each part helps avoid mistakes and design your table properly. You’ll need to decide on the table name, key schema, attribute types, and capacity options — either on-demand or provisioned throughput.

For example, to create a Users table where UserId is the unique identifier, use:

aws dynamodb create-table \
  --table-name Users \
  --attribute-definitions AttributeName=UserId,AttributeType=S \
  --key-schema AttributeName=UserId,KeyType=HASH \
  --billing-mode PAY_PER_REQUEST

This setup defines UserId as a string and uses it as the partition key. The PAY_PER_REQUEST billing mode means you’re charged based on usage, without pre-allocating read/write units. To manage capacity yourself, switch to provisioned throughput by adding:

--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

For complex scenarios, define a composite primary key and add secondary indexes. For instance, create an Orders table with OrderId as the partition key, CustomerId as the sort key, and a global secondary index:

aws dynamodb create-table \
  --table-name Orders \
  --attribute-definitions \
    AttributeName=OrderId,AttributeType=S \
    AttributeName=CustomerId,AttributeType=S \
  --key-schema \
    AttributeName=OrderId,KeyType=HASH \
    AttributeName=CustomerId,KeyType=RANGE \
  --billing-mode PAY_PER_REQUEST \
  --global-secondary-indexes \
    '[{
      "IndexName":"CustomerIndex",
      "KeySchema":[{"AttributeName":"CustomerId","KeyType":"HASH"}],
      "Projection":{"ProjectionType":"ALL"}
    }]'

This approach provides flexibility while keeping your data organized for efficient access.

Verifying Table Creation

After running the create-table command, the CLI returns a JSON output describing the table’s properties. The table creation process is asynchronous, starting with a status of CREATING. Check its status with:

aws dynamodb describe-table --table-name Users

This output includes the current status. Once it changes to ACTIVE, the table is ready for use. List all your tables using:

aws dynamodb list-tables

Updating a Table

Sometimes, you need to make changes to an existing table. While primary keys cannot be changed directly, you can adjust provisioned throughput (if not using on-demand mode), add or delete global secondary indexes, and modify table capacity. To increase write capacity:

aws dynamodb update-table \
    --table-name Users \
    --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=10

To add a global secondary index:

aws dynamodb update-table \
    --table-name Users \
    --attribute-definitions AttributeName=Email,AttributeType=S \
    --global-secondary-index-updates \
        '[{
            "Create": {
                "IndexName": "EmailIndex",
                "KeySchema": [
                    {"AttributeName":"Email","KeyType":"HASH"}
                ],
                "Projection": {
                    "ProjectionType":"ALL"
                },
                "ProvisionedThroughput": {
                    "ReadCapacityUnits": 5,
                    "WriteCapacityUnits": 5
                }
            }
        }]'

This adds an index called EmailIndex for efficient email lookups. Monitor its status using the describe-table command.

Deleting a Table

When you no longer need a table, remove it easily with:

aws dynamodb delete-table --table-name Users

This deletes the table and all its data. Be cautious, as the data cannot be recovered after deletion.

Backing Up and Restoring

Regular backups are a good practice. Create on-demand backups using:

aws dynamodb create-backup --table-name Users --backup-name UsersBackup

The output provides a BackupArn, which you can use to restore the backup later:

aws dynamodb restore-table-from-backup \
    --target-table-name UsersRestored \
    --backup-arn <BackupArn>

This creates a new table from the backup. Use point-in-time recovery, if enabled, to restore the table to any moment within the last 35 days.

Monitoring Tables

Monitoring is crucial for managing DynamoDB tables. The CLI allows you to enable or disable point-in-time recovery, check the table’s status, and view metrics via CloudWatch. Enable point-in-time recovery with:

aws dynamodb update-continuous-backups \
    --table-name Users \
    --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true

Use CloudWatch to monitor read and write throughput, throttled requests, and other key metrics to keep tables healthy and performant.

Conclusion

Managing DynamoDB tables through the AWS CLI offers flexibility and efficiency for developers and administrators who prefer working in a terminal. From creating simple tables to defining complex schemas with indexes, the CLI provides clear commands that can be integrated into scripts and workflows. Backing up and restoring data, adjusting throughput, and monitoring tables become much simpler with these commands. This hands-on approach helps you stay close to your infrastructure and gain confidence in how your data is organized and maintained.

For more detailed information on AWS CLI commands for DynamoDB, check out the official AWS CLI documentation.