aux4/db-dynamodb

DynamoDB database tools

This package provides a small set of aux4 commands to interact with AWS DynamoDB. It exposes commonly used operations (scan, query, get, put, update, delete), batch stream helpers (stream-write, stream-read) and simple table management commands intended for testing with local DynamoDB instances. Use it for quick CLI-driven DynamoDB tasks, test setups, or to power automation scripts inside the aux4 ecosystem.

It integrates with aux4 variable interpolation and supports streaming JSON/NJSON input for batch operations. The package is focused on developer convenience (local testing, batch imports/exports) while remaining usable with standard AWS credentials and regions.

Installation

aux4 aux4 pkger install aux4/db-dynamodb

Quick Start

The most common operation is scanning a table. This example runs a scan against "my-table" using the default region:

aux4 db dynamodb scan my-table --region us-east-1

This runs a DynamoDB scan and prints matched items as JSON to stdout. Omit --region to use the default region (us-east-1), or provide --profile to use a named AWS CLI profile.

Note: to target a local DynamoDB instance use --endpointUrl <URL> (for example: http://127.0.0.1:8000).

Basic single-item operations

Overview

  • Put: insert or replace an item (reads JSON from stdin)
  • Get: retrieve a single item by key
  • Delete: remove an item by key

Put an item by piping JSON into the command:

echo '{"id":"user1","name":"John","age":28,"email":"john@example.com"}' \
  | aux4 db dynamodb put test-users --region us-east-1

Retrieve the item by primary key (single key "id"):

aux4 db dynamodb get test-users --key id --id user1 --region us-east-1 | jq .

Delete the item by key:

aux4 db dynamodb delete test-users --key id --id user1 --region us-east-1

For composite keys, pass multiple key field names to --key and supply the matching values as flags (one per key name).

Update specific attributes of an item without replacing the whole item, using a DynamoDB update expression. Unlike put (which overwrites the entire item), update performs an atomic partial modification and prints the updated item (ALL_NEW):

aux4 db dynamodb update test-users --key id --id user1 \
  --updateExpression "SET age = :a" \
  --attributeValues '{":a": 29}' --region us-east-1

Use --attributeNames for reserved keywords, and combine SET/REMOVE/ADD clauses in one expression:

aux4 db dynamodb update test-users --key id --id user1 \
  --updateExpression "SET #n = :n REMOVE obsolete" \
  --attributeNames '{"#n": "name"}' \
  --attributeValues '{":n": "Jane"}' --region us-east-1

For command reference see:

  • aux4 db dynamodb scan
  • aux4 db dynamodb get
  • aux4 db dynamodb put
  • aux4 db dynamodb delete
  • aux4 db dynamodb update

Stream and batch operations

Overview

  • stream-write: accept a JSON array or newline-delimited JSON (NJSON) on stdin and write items in batches (default batch size 25).
  • stream-read: accept a JSON array or NJSON of key objects on stdin and perform batch-get operations, emitting items found.

Write a JSON array of items into a table:

echo '[{"id":"array1","name":"Array User 1","age":25},{"id":"array2","name":"Array User 2","age":30}]' \
  | aux4 db dynamodb stream-write test-stream-array --region us-east-1

Write newline-delimited JSON (NJSON) into a table (use --stream true):

echo '{"id":"njson1","name":"NJSON User 1","age":28}
{"id":"njson2","name":"NJSON User 2","age":32}' \
  | aux4 db dynamodb stream-write test-stream-njson --stream true --region us-east-1

Batch-read multiple keys supplied as a JSON array:

echo '[{"id":"array1"},{"id":"array2"}]' | aux4 db dynamodb stream-read test-stream-array --region us-east-1 | jq .

Batch-read using NJSON keys:

echo '{"id":"njson1"}
{"id":"njson2"}' | aux4 db dynamodb stream-read test-stream-njson --stream true --region us-east-1 | jq .

For stream-write, default batchSize is 25 (DynamoDB batch-write-item max 25). For stream-read, default batchSize is 100 (DynamoDB batch-get-item max 100).

For command reference see:

  • aux4 db dynamodb stream-write
  • aux4 db dynamodb stream-read

Table management (testing helpers)

Overview

  • create-table and delete-table are convenient helpers intended for local/testing workflows. They accept keySchema, attributeDefinitions, and billingMode.

Create a simple table (example with a single-string primary key):

aux4 db dynamodb create-table test-users \
  --keySchema '[{"AttributeName":"id","KeyType":"HASH"}]' \
  --attributeDefinitions '[{"AttributeName":"id","AttributeType":"S"}]' \
  --billingMode PAY_PER_REQUEST \
  --region us-east-1

Delete the table:

aux4 db dynamodb delete-table test-users --region us-east-1

These commands are convenient when running local DynamoDB instances during tests. Use the --endpointUrl flag to point to a local endpoint if needed.

For command reference see:

  • aux4 db dynamodb create-table
  • aux4 db dynamodb delete-table

Variables and flags

Common variables (available across subcommands)

  • table (positional argument) — DynamoDB table name (required)
  • region — AWS region (default: us-east-1)
  • profile — AWS profile (default: "")
  • endpointUrl — DynamoDB endpoint URL (default: "")
  • filter — Filter expression for scan/query (default: "")
  • keyCondition — Key condition expression (query) (default: "")
  • attributeNames — Expression attribute names (JSON) (default: "")
  • attributeValues — Expression attribute values (JSON) (default: "")
  • key — Key field names (comma-separated) (get/delete/update)
  • updateExpression — Update expression, e.g. SET latest = :v (update) (default: "")
  • stream — Input format for stream commands: true for NJSON, false for JSON array (default: false)
  • batchSize — Items per batch (stream-write max 25; stream-read max 100)

Required vs optional: table is positional and required for most commands. Most other flags are optional; region defaults to us-east-1. Use --key for get/delete when the primary key has multiple attributes.

Examples

Basic single-item workflow

Create a table, put an item, get it back, then clean up. These commands run against your configured AWS environment unless an endpoint is supplied.

aux4 db dynamodb create-table test-users --region us-east-1
echo '{"id":"user1","name":"John","age":28}' | aux4 db dynamodb put test-users --region us-east-1
aux4 db dynamodb get test-users --key id --id user1 --region us-east-1 | jq .
aux4 db dynamodb delete test-users --region us-east-1

This sequence creates test-users, inserts a single item, retrieves it as JSON, and removes the table.

Stream write + stream read (JSON array)

Write multiple items in one JSON array and then read them back by keys.

echo '[{"id":"array1","name":"Array User 1","age":25},{"id":"array2","name":"Array User 2","age":30}]' \
  | aux4 db dynamodb stream-write test-stream-array --region us-east-1

echo '[{"id":"array1"},{"id":"array2"}]' \
  | aux4 db dynamodb stream-read test-stream-array --region us-east-1 | jq .

The stream-read command returns the full items found in the table.

Stream write + stream read (NJSON)

Use newline-delimited JSON to write and read when working with streaming workflows.

echo '{"id":"njson1","name":"NJSON User 1","age":28}
{"id":"njson2","name":"NJSON User 2","age":32}' \
  | aux4 db dynamodb stream-write test-stream-njson --stream true --region us-east-1

echo '{"id":"njson1"}
{"id":"njson2"}' | aux4 db dynamodb stream-read test-stream-njson --stream true --region us-east-1 | jq .

This writes two NJSON items and then retrieves them; stream-read emits each item as JSON (newline-separated when --stream true).

Troubleshooting notes

  • ResourceNotFoundException typically means the table does not exist — double-check table name and region, or create the table before querying.
  • Invalid JSON input errors occur when commands that read stdin receive invalid JSON. Ensure correct quoting and that piped JSON is valid.
  • For local testing, pass --endpointUrl <your-local-endpoint> (for example: http://127.0.0.1:8000). Do not include local endpoint values unless you intend to target a local DynamoDB instance.

License

This package is licensed under the Apache License, Version 2.0.

See LICENSE for details.