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 <command> [<options>]
or
aws dynamodb help

<command>: Represents a specific DynamoDB operation (e.g., create-table, get-item, list-tables).
<options>: Consists of global AWS CLI options and operation-specific parameters.

PARAMETERS

--region
    Specifies the AWS region to send the request to. E.g., us-east-1.

--output
    The output format for the command's results. Can be json, text, or table.

--profile
    Uses a specific profile from your shared credential file or configuration file. E.g., my-dev-profile.

--endpoint-url
    Overrides the default service endpoint URL. Useful for local DynamoDB instances or custom endpoints.

--no-paginate
    Disables client-side pagination, causing all results to be returned in a single response.

--cli-input-json
    Reads arguments for an operation from a specified JSON file. Useful for complex inputs.

--generate-cli-skeleton
    Prints a JSON skeleton for parameters to an operation, which can be used with --cli-input-json.

Operation-Specific Parameters
    Note that each specific DynamoDB operation (e.g., create-table, get-item, update-item) has its own unique set of mandatory and optional parameters (e.g., --table-name, --key, --attribute-definitions). These are highly dependent on the chosen operation.

DESCRIPTION

The aws dynamodb command is a crucial subcommand within the official AWS Command Line Interface (CLI), enabling direct programmatic interaction with Amazon DynamoDB from your Linux terminal. It allows you to perform a wide range of database operations, including creating, listing, describing, and deleting tables; putting, getting, updating, and deleting items; and managing various DynamoDB features like global secondary indexes, streams, and backups. This command provides a powerful alternative to the AWS Management Console for automating DynamoDB tasks, scripting database migrations, and integrating with CI/CD pipelines. It leverages the AWS SDKs underneath, ensuring secure and scalable access to your DynamoDB instances. Proper AWS CLI configuration (including credentials and region) is essential for its successful execution.

CAVEATS

The command "aws-dynamodb" as a standalone executable does not exist. It refers to the dynamodb subcommand within the aws CLI tool. Therefore, you must have the AWS CLI installed and configured on your system. Operations specific to DynamoDB, such as create-table or get-item, are invoked as subcommands of aws dynamodb. Each of these specific operations has its own set of mandatory and optional parameters.

DISCOVERING OPERATIONS

To see all available DynamoDB operations, run:
aws dynamodb help
For details on a specific operation (e.g., create-table), run:
aws dynamodb create-table help

PERMISSIONS

Ensure the AWS credentials configured for your CLI session have the necessary IAM permissions to perform the desired DynamoDB actions (e.g., dynamodb:CreateTable, dynamodb:GetItem).

ERROR HANDLING

The AWS CLI returns standard exit codes. A non-zero exit code indicates an error. Error messages provide details on common issues like missing parameters, invalid values, or permission denied errors.

HISTORY

The AWS CLI was first released in 2013, providing a unified command-line interface for managing all AWS services. The dynamodb subcommand has been a core component since its early versions, evolving alongside the DynamoDB service itself. Regular updates ensure compatibility with new DynamoDB features and improvements in CLI functionality and user experience.

SEE ALSO

aws(1): The main entry point for the AWS Command Line Interface., aws configure(1): Configures AWS credentials and default settings., jq(1): A lightweight and flexible command-line JSON processor, often used with AWS CLI output.

Copied to clipboard