Created
April 17, 2026 01:18
-
-
Save jonmoshier/2b54ada9ccb434a63e211bd7429e11a3 to your computer and use it in GitHub Desktop.
lsd — friendly DynamoDB CLI wrappers for AWS CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lsd — friendly DynamoDB CLI wrappers | |
| # Usage: lsd [subcommand] [args] | |
| # lsd list all tables | |
| # lsd info <table> describe a table (schema, keys, indexes) | |
| # lsd scan <table> [n] scan up to n items (default 20) | |
| # lsd get <table> <k> <v> get a single item by partition key | |
| # lsd keys <table> show just the key schema | |
| # lsd count <table> approximate item count | |
| # lsd help show this help | |
| lsd() { | |
| local cmd="${1:-list}" | |
| case "$cmd" in | |
| list|"") | |
| echo "" | |
| aws dynamodb list-tables \ | |
| --query 'TableNames[]' \ | |
| --output text \ | |
| | tr '\t' '\n' \ | |
| | sort \ | |
| | while read -r name; do | |
| local count | |
| count=$(aws dynamodb describe-table \ | |
| --table-name "$name" \ | |
| --query 'Table.ItemCount' \ | |
| --output text 2>/dev/null) | |
| printf " %-40s %s items\n" "$name" "$count" | |
| done | |
| echo "" | |
| ;; | |
| info) | |
| local table="${2:?Usage: lsd info <table>}" | |
| echo "" | |
| aws dynamodb describe-table --table-name "$table" \ | |
| --query '{ | |
| Table: Table.TableName, | |
| Status: Table.TableStatus, | |
| Items: Table.ItemCount, | |
| SizeBytes: Table.TableSizeBytes, | |
| Keys: Table.KeySchema, | |
| Attributes: Table.AttributeDefinitions, | |
| GSIs: Table.GlobalSecondaryIndexes[].IndexName, | |
| LSIs: Table.LocalSecondaryIndexes[].IndexName | |
| }' \ | |
| --output yaml | |
| echo "" | |
| ;; | |
| scan) | |
| local table="${2:?Usage: lsd scan <table> [limit]}" | |
| local limit="${3:-20}" | |
| echo "" | |
| echo "Scanning $table (limit: $limit)..." | |
| echo "" | |
| aws dynamodb scan \ | |
| --table-name "$table" \ | |
| --max-items "$limit" \ | |
| --output json \ | |
| | python3 -c " | |
| import json, sys | |
| data = json.load(sys.stdin) | |
| items = data.get('Items', []) | |
| print(f'{len(items)} items returned') | |
| print() | |
| for i, item in enumerate(items, 1): | |
| flat = {k: list(v.values())[0] for k, v in item.items()} | |
| print(f'[{i}]', json.dumps(flat, indent=2, default=str)) | |
| print() | |
| " | |
| ;; | |
| get) | |
| local table="${2:?Usage: lsd get <table> <key> <value>}" | |
| local key="${3:?Usage: lsd get <table> <key> <value>}" | |
| local value="${4:?Usage: lsd get <table> <key> <value>}" | |
| echo "" | |
| local key_type | |
| key_type=$(aws dynamodb describe-table --table-name "$table" \ | |
| --query "Table.AttributeDefinitions[?AttributeName=='$key'].AttributeType" \ | |
| --output text) | |
| local type_map="S" | |
| [[ "$key_type" == "N" ]] && type_map="N" | |
| [[ "$key_type" == "B" ]] && type_map="B" | |
| aws dynamodb get-item \ | |
| --table-name "$table" \ | |
| --key "{\"$key\": {\"$type_map\": \"$value\"}}" \ | |
| --output json \ | |
| | python3 -c " | |
| import json, sys | |
| data = json.load(sys.stdin) | |
| item = data.get('Item') | |
| if not item: | |
| print('No item found.') | |
| else: | |
| flat = {k: list(v.values())[0] for k, v in item.items()} | |
| print(json.dumps(flat, indent=2, default=str)) | |
| " | |
| echo "" | |
| ;; | |
| keys) | |
| local table="${2:?Usage: lsd keys <table>}" | |
| echo "" | |
| aws dynamodb describe-table --table-name "$table" \ | |
| --query '{Keys: Table.KeySchema, Attributes: Table.AttributeDefinitions}' \ | |
| --output yaml | |
| echo "" | |
| ;; | |
| count) | |
| local table="${2:?Usage: lsd count <table>}" | |
| local count | |
| count=$(aws dynamodb describe-table --table-name "$table" \ | |
| --query 'Table.ItemCount' --output text) | |
| echo "" | |
| echo " $table: ~$count items (approximate)" | |
| echo "" | |
| ;; | |
| help|--help|-h) | |
| echo "" | |
| echo " lsd list all tables" | |
| echo " lsd info <table> describe table schema and indexes" | |
| echo " lsd scan <table> [n] scan up to n items (default 20)" | |
| echo " lsd get <table> <k> <v> get item by partition key" | |
| echo " lsd keys <table> show key schema only" | |
| echo " lsd count <table> approximate item count" | |
| echo " lsd help show this help" | |
| echo "" | |
| ;; | |
| *) | |
| echo "Unknown command: $cmd. Run 'lsd help' for usage." | |
| return 1 | |
| ;; | |
| esac | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment