LinuxCommandLibrary

aws-dynamodb

Interact with Amazon DynamoDB from the command line

TLDR

Create a table

$ aws dynamodb create-table --table-name [table_name] --attribute-definitions [AttributeName=S,AttributeType=S] --key-schema [AttributeName=S,KeyType=HASH] --provisioned-throughput [ReadCapacityUnits=5,WriteCapacityUnits=5]
copy

List all tables in the DynamoDB
$ aws dynamodb list-tables
copy

Get details about a specific table
$ aws dynamodb describe-table --table-name [table_name]
copy

Add an item to a table
$ aws dynamodb put-item --table-name [table_name] --item '[{"AttributeName": {"S": "value"]]'
copy

Retrieve an item from a table
$ aws dynamodb get-item --table-name [table_name] --key '[{"ID": {"N": "1"]]'
copy

Update an item in the table
$ aws dynamodb update-item --table-name [table_name] --key '[{"ID": {"N": "1"]]' --update-expression "[SET Name = :n]" --expression-attribute-values '[{":n": {"S": "Jane"]]'
copy

Scan items in the table
$ aws dynamodb scan --table-name [table_name]
copy

Delete an item from the table
$ aws dynamodb delete-item --table-name [table_name] --key '[{"ID": {"N": "1"]]'
copy

SYNOPSIS

aws dynamodb SUBCOMMAND [--table-name NAME] [--region REGION] [OPTIONS]

PARAMETERS

--table-name (string)
    Name of the DynamoDB table

--key (structure)
    Primary key of the item in JSON format

--item (structure)
    Item attributes to put or update in JSON

--region (string)
    AWS Region (e.g., us-east-1)

--endpoint-url (string)
    Override AWS service endpoint

--profile (string)
    Named profile from AWS config

--output (string)
    Output format: json|text|table

--query (string)
    JMESPath query to filter output

--cli-input-json (string)
    Perform operation from JSON file

--generate-cli-skeleton (string)
    Print JSON skeleton for input

--debug
    Enable debug logging

--condition-expression (string)
    Conditional expression for writes

--projection-expression (string)
    Attributes to retrieve

--filter-expression (string)
    Filter for scan or query

--limit (integer)
    Max number of items to evaluate

DESCRIPTION

The aws dynamodb command is a core component of the AWS Command Line Interface (CLI), enabling direct interaction with Amazon DynamoDB, a fully managed, serverless NoSQL database service.

It supports a wide range of operations including creating and managing tables, inserting, retrieving, updating, and deleting items, as well as querying and scanning data. Subcommands handle schema definitions with primary keys, attributes, throughput settings, global secondary indexes (GSI), local secondary indexes (LSI), and streams.

Data is exchanged in JSON format, supporting native types like strings, numbers, binaries, lists, maps, sets, booleans, and nulls. Batch operations allow efficient handling of multiple items. Conditional expressions enable atomic, optimistic concurrency control.

Ideal for automation, scripting, data migration, testing with DynamoDB Local, and integration in DevOps pipelines. Output formats include JSON, text, or table for parsing with tools like jq. All actions require AWS credentials configured via IAM roles, access keys, or profiles, and incur standard DynamoDB pricing based on read/write capacity units and storage.

Usage requires AWS CLI v2 recommended for performance gains over v1. Global options control verbosity, pagination, and endpoints.

CAVEATS

Requires AWS CLI installed/configured with credentials; operations billed by AWS; large scans/queries consume read capacity; pagination needed for big result sets; JSON input must match DynamoDB types exactly.

KEY SUBCOMMANDS

create-table, delete-table, describe-table, get-item, put-item, update-item, delete-item, batch-get-item, batch-write-item, query, scan, list-tables.

INSTALLATION

curl 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip' | unzip -; sudo ./aws/install --bin-dir /usr/local/bin

EXAMPLES

Get item: aws dynamodb get-item --table-name Users --key '{"id":{"S":"123"}}'
Create table: aws dynamodb create-table --table-name Test --attribute-definitions AttributeName=id,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

HISTORY

Introduced in AWS CLI v1 (March 2013) alongside DynamoDB launch; enhanced in v2 (2020) with faster execution, modular design, and better JSON handling; ongoing updates track DynamoDB features like on-demand capacity (2018) and PartiQL support.

SEE ALSO

aws(1), aws s3(1), aws rds(1), jq(1), dynamodb-local(1)

Copied to clipboard