jpskill.com
🛠️ 開発・MCP コミュニティ

aws-dynamodb

Amazon DynamoDBを活用し、高速かつ柔軟なNoSQLデータベースを構築、パーティションキーやソートキーでテーブル設計、GSI/LSIで多様なクエリに対応、データ変更を捉えるストリームを有効化、効率的なデータモデリングのためにシングルテーブル設計を適用するSkill。

📜 元の英語説明(参考)

Build with Amazon DynamoDB for fast, scalable NoSQL storage. Design tables with partition and sort keys, create GSI and LSI for flexible queries, enable streams for change data capture, and apply single-table design patterns for efficient data modeling.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Amazon DynamoDBを活用し、高速かつ柔軟なNoSQLデータベースを構築、パーティションキーやソートキーでテーブル設計、GSI/LSIで多様なクエリに対応、データ変更を捉えるストリームを有効化、効率的なデータモデリングのためにシングルテーブル設計を適用するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o aws-dynamodb.zip https://jpskill.com/download/14665.zip && unzip -o aws-dynamodb.zip && rm aws-dynamodb.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14665.zip -OutFile "$d\aws-dynamodb.zip"; Expand-Archive "$d\aws-dynamodb.zip" -DestinationPath $d -Force; ri "$d\aws-dynamodb.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して aws-dynamodb.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → aws-dynamodb フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

AWS DynamoDB

Amazon DynamoDB は、フルマネージドな NoSQL キーバリューおよびドキュメントデータベースです。自動スケーリング、組み込みのセキュリティ、および運用上のオーバーヘッドなしで、あらゆる規模で1桁ミリ秒のレイテンシーを実現します。

コアコンセプト

  • Table — アイテム(行)のコレクション
  • Partition Key (PK) — データの分散に必要なプライマリキー
  • Sort Key (SK) — オプション。パーティション内の範囲クエリを有効にします
  • GSI — Global Secondary Index。異なるアクセスパターンのための代替 PK/SK
  • LSI — Local Secondary Index。同じ PK だが異なる SK (テーブル作成時に作成する必要があります)
  • Streams — イベント駆動型処理のためのアイテム変更の順序付きログ
  • TTL — 自動アイテム有効期限

テーブルの作成

# パーティションキーとソートキーを持つテーブルを作成する
aws dynamodb create-table \
  --table-name Orders \
  --attribute-definitions \
    AttributeName=PK,AttributeType=S \
    AttributeName=SK,AttributeType=S \
  --key-schema \
    AttributeName=PK,KeyType=HASH \
    AttributeName=SK,KeyType=RANGE \
  --billing-mode PAY_PER_REQUEST \
  --tags Key=Env,Value=prod
# プロビジョニングされたキャパシティと GSI を持つテーブルを作成する
aws dynamodb create-table \
  --table-name Orders \
  --attribute-definitions \
    AttributeName=PK,AttributeType=S \
    AttributeName=SK,AttributeType=S \
    AttributeName=GSI1PK,AttributeType=S \
    AttributeName=GSI1SK,AttributeType=S \
  --key-schema \
    AttributeName=PK,KeyType=HASH \
    AttributeName=SK,KeyType=RANGE \
  --global-secondary-indexes '[{
    "IndexName": "GSI1",
    "KeySchema": [
      {"AttributeName":"GSI1PK","KeyType":"HASH"},
      {"AttributeName":"GSI1SK","KeyType":"RANGE"}
    ],
    "Projection": {"ProjectionType":"ALL"},
    "ProvisionedThroughput": {"ReadCapacityUnits":5,"WriteCapacityUnits":5}
  }]' \
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

シングルテーブル設計

# シングルテーブル設計 — 複数のエンティティタイプを1つのテーブルに格納する
import boto3
from datetime import datetime

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AppData')

# 顧客を格納する
table.put_item(Item={
    'PK': 'CUSTOMER#C001',
    'SK': 'PROFILE',
    'name': 'Alice Johnson',
    'email': 'alice@example.com',
    'GSI1PK': 'CUSTOMERS',
    'GSI1SK': 'Alice Johnson',
    'entity_type': 'Customer'
})

# その顧客の注文を格納する
table.put_item(Item={
    'PK': 'CUSTOMER#C001',
    'SK': 'ORDER#2024-01-15#O001',
    'total': 149.99,
    'status': 'shipped',
    'GSI1PK': 'ORDER#O001',
    'GSI1SK': 'CUSTOMER#C001',
    'entity_type': 'Order'
})

# 顧客のすべての注文をクエリする (日付でソート)
response = table.query(
    KeyConditionExpression='PK = :pk AND begins_with(SK, :sk)',
    ExpressionAttributeValues={':pk': 'CUSTOMER#C001', ':sk': 'ORDER#'}
)

CRUD 操作

# アイテムを配置する
aws dynamodb put-item \
  --table-name Orders \
  --item '{
    "PK": {"S": "CUSTOMER#C001"},
    "SK": {"S": "ORDER#2024-01-15#O001"},
    "total": {"N": "149.99"},
    "status": {"S": "pending"}
  }'
# キーでアイテムを取得する
aws dynamodb get-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}'
# 条件式でアイテムを更新する
aws dynamodb update-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}' \
  --update-expression "SET #s = :new_status, updated_at = :ts" \
  --condition-expression "#s = :old_status" \
  --expression-attribute-names '{"#s":"status"}' \
  --expression-attribute-values '{":new_status":{"S":"shipped"},":old_status":{"S":"pending"},":ts":{"S":"2024-01-16T10:00:00Z"}}'
# アイテムを削除する
aws dynamodb delete-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}'

クエリとスキャン

# ソートキー条件でクエリする
aws dynamodb query \
  --table-name Orders \
  --key-condition-expression "PK = :pk AND begins_with(SK, :prefix)" \
  --expression-attribute-values '{":pk":{"S":"CUSTOMER#C001"},":prefix":{"S":"ORDER#2024"}}' \
  --scan-index-forward false \
  --limit 10
# GSI をクエリする
aws dynamodb query \
  --table-name Orders \
  --index-name GSI1 \
  --key-condition-expression "GSI1PK = :pk" \
  --expression-attribute-values '{":pk":{"S":"ORDER#O001"}}'

バッチ処理

# バッチ書き込み (最大25アイテム)
import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AppData')

with table.batch_writer() as batch:
    for i in range(100):
        batch.put_item(Item={
            'PK': f'PRODUCT#P{i:04d}',
            'SK': 'DETAILS',
            'name': f'Product {i}',
            'price': round(9.99 + i * 0.5, 2)
        })

DynamoDB Streams

# テーブルでストリームを有効にする
aws dynamodb update-table \
  --table-name Orders \
  --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES
# DynamoDB ストリームイベントの Lambda ハンドラー
import json

def handler(event, context):
    for record in event['Records']:
        event_name = record['eventName']  # INSERT, MODIFY, REMOVE
        new_image = record['dynamodb'].get('NewImage', {})
        old_image = record['dynamodb'].get('OldImage', {})

        if event_name == 'MODIFY':
            old_status = old_image.get('status', {}).get('S')
            new_status = new_image.get('status', {}).get('S')
            if old_status != new_status:
                print(f"Status changed: {old_status} -> {new_status}")
                # ダウンストリーム処理をトリガーする

TTL (Time to Live)

# 属性で TTL を有効にする
aws dynamodb update-time-to-live \
  --table-name Sessions \
  --time-to-live-specification Enabled=true,AttributeName=expires_at
# アイテムの書き込み時に TTL を設定する (エポックタイムスタンプ)
import time

table.put_item(Item={
    'PK': 'SESSION#abc123',
    'SK': 'DATA',
    'user_id': 'U001',
    'expires_at': int(t
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

AWS DynamoDB

Amazon DynamoDB is a fully managed NoSQL key-value and document database. It delivers single-digit millisecond latency at any scale with automatic scaling, built-in security, and zero operational overhead.

Core Concepts

  • Table — a collection of items (rows)
  • Partition Key (PK) — required primary key for distributing data
  • Sort Key (SK) — optional, enables range queries within a partition
  • GSI — Global Secondary Index, alternate PK/SK for different access patterns
  • LSI — Local Secondary Index, same PK but different SK (must be created at table creation)
  • Streams — ordered log of item changes for event-driven processing
  • TTL — automatic item expiration

Creating Tables

# Create a table with partition key and sort key
aws dynamodb create-table \
  --table-name Orders \
  --attribute-definitions \
    AttributeName=PK,AttributeType=S \
    AttributeName=SK,AttributeType=S \
  --key-schema \
    AttributeName=PK,KeyType=HASH \
    AttributeName=SK,KeyType=RANGE \
  --billing-mode PAY_PER_REQUEST \
  --tags Key=Env,Value=prod
# Create table with provisioned capacity and GSI
aws dynamodb create-table \
  --table-name Orders \
  --attribute-definitions \
    AttributeName=PK,AttributeType=S \
    AttributeName=SK,AttributeType=S \
    AttributeName=GSI1PK,AttributeType=S \
    AttributeName=GSI1SK,AttributeType=S \
  --key-schema \
    AttributeName=PK,KeyType=HASH \
    AttributeName=SK,KeyType=RANGE \
  --global-secondary-indexes '[{
    "IndexName": "GSI1",
    "KeySchema": [
      {"AttributeName":"GSI1PK","KeyType":"HASH"},
      {"AttributeName":"GSI1SK","KeyType":"RANGE"}
    ],
    "Projection": {"ProjectionType":"ALL"},
    "ProvisionedThroughput": {"ReadCapacityUnits":5,"WriteCapacityUnits":5}
  }]' \
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Single-Table Design

# Single-table design — store multiple entity types in one table
import boto3
from datetime import datetime

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AppData')

# Store a customer
table.put_item(Item={
    'PK': 'CUSTOMER#C001',
    'SK': 'PROFILE',
    'name': 'Alice Johnson',
    'email': 'alice@example.com',
    'GSI1PK': 'CUSTOMERS',
    'GSI1SK': 'Alice Johnson',
    'entity_type': 'Customer'
})

# Store an order for that customer
table.put_item(Item={
    'PK': 'CUSTOMER#C001',
    'SK': 'ORDER#2024-01-15#O001',
    'total': 149.99,
    'status': 'shipped',
    'GSI1PK': 'ORDER#O001',
    'GSI1SK': 'CUSTOMER#C001',
    'entity_type': 'Order'
})

# Query all orders for a customer (sorted by date)
response = table.query(
    KeyConditionExpression='PK = :pk AND begins_with(SK, :sk)',
    ExpressionAttributeValues={':pk': 'CUSTOMER#C001', ':sk': 'ORDER#'}
)

CRUD Operations

# Put an item
aws dynamodb put-item \
  --table-name Orders \
  --item '{
    "PK": {"S": "CUSTOMER#C001"},
    "SK": {"S": "ORDER#2024-01-15#O001"},
    "total": {"N": "149.99"},
    "status": {"S": "pending"}
  }'
# Get an item by key
aws dynamodb get-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}'
# Update an item with conditional expression
aws dynamodb update-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}' \
  --update-expression "SET #s = :new_status, updated_at = :ts" \
  --condition-expression "#s = :old_status" \
  --expression-attribute-names '{"#s":"status"}' \
  --expression-attribute-values '{":new_status":{"S":"shipped"},":old_status":{"S":"pending"},":ts":{"S":"2024-01-16T10:00:00Z"}}'
# Delete an item
aws dynamodb delete-item \
  --table-name Orders \
  --key '{"PK":{"S":"CUSTOMER#C001"},"SK":{"S":"ORDER#2024-01-15#O001"}}'

Queries and Scans

# Query with sort key condition
aws dynamodb query \
  --table-name Orders \
  --key-condition-expression "PK = :pk AND begins_with(SK, :prefix)" \
  --expression-attribute-values '{":pk":{"S":"CUSTOMER#C001"},":prefix":{"S":"ORDER#2024"}}' \
  --scan-index-forward false \
  --limit 10
# Query a GSI
aws dynamodb query \
  --table-name Orders \
  --index-name GSI1 \
  --key-condition-expression "GSI1PK = :pk" \
  --expression-attribute-values '{":pk":{"S":"ORDER#O001"}}'

Batch Operations

# Batch write (up to 25 items)
import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AppData')

with table.batch_writer() as batch:
    for i in range(100):
        batch.put_item(Item={
            'PK': f'PRODUCT#P{i:04d}',
            'SK': 'DETAILS',
            'name': f'Product {i}',
            'price': round(9.99 + i * 0.5, 2)
        })

DynamoDB Streams

# Enable streams on a table
aws dynamodb update-table \
  --table-name Orders \
  --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES
# Lambda handler for DynamoDB stream events
import json

def handler(event, context):
    for record in event['Records']:
        event_name = record['eventName']  # INSERT, MODIFY, REMOVE
        new_image = record['dynamodb'].get('NewImage', {})
        old_image = record['dynamodb'].get('OldImage', {})

        if event_name == 'MODIFY':
            old_status = old_image.get('status', {}).get('S')
            new_status = new_image.get('status', {}).get('S')
            if old_status != new_status:
                print(f"Status changed: {old_status} -> {new_status}")
                # Trigger downstream processing

TTL (Time to Live)

# Enable TTL on an attribute
aws dynamodb update-time-to-live \
  --table-name Sessions \
  --time-to-live-specification Enabled=true,AttributeName=expires_at
# Set TTL when writing items (epoch timestamp)
import time

table.put_item(Item={
    'PK': 'SESSION#abc123',
    'SK': 'DATA',
    'user_id': 'U001',
    'expires_at': int(time.time()) + 86400  # 24 hours from now
})

Best Practices

  • Design for access patterns first, not entity relationships
  • Use single-table design to minimize the number of requests
  • Use begins_with on sort keys for hierarchical data queries
  • Enable on-demand (PAY_PER_REQUEST) for unpredictable workloads
  • Use GSIs sparingly — each one duplicates data and costs extra
  • Enable DynamoDB Streams + Lambda for event-driven reactions
  • Use TTL to auto-expire temporary data (sessions, caches)
  • Use condition expressions to prevent write conflicts