跳到正文
cccskills
免费在 GitHub 公开

aws-dynamodb

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.

中文简介正在准备中。当前显示原文说明。

集成工具AWS
查看安装方法

包含的文件(2)

  • SKILL.md6.9 KB
  • _scores.json1.6 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Scripts and configures production rendering in Autodesk 3ds Max with the V-Ray and Corona renderers: output size and files, render elements, denoising, light mix, batch and command-line rendering, and network rendering. Use when a user asks to set up a production render, render several cameras in one batch, render from the command line or on a render farm, add render passes for compositing, or cut render time for archviz and product shots.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

Covers scripting Autodesk 3ds Max, the 3D modeling and rendering application, with MAXScript and Python (pymxs): scene manipulation, object creation, material assignment, camera and light setup, batch operations, and file I/O. Use when tasks involve automating repetitive 3ds Max workflows, batch processing scenes, running scripts headless with 3dsmaxbatch, creating custom tools, or scripting scene setup for archviz, product visualization, or VFX.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

3proxy

免费

3proxy is a small open-source proxy server that runs HTTP/HTTPS, SOCKS4/5, SNI and TCP/UDP port-mapping proxies from one config file. Use when a user asks to set up an HTTP or SOCKS5 proxy, add proxy users and passwords, write 3proxy access rules, chain or rotate upstream (parent) proxies, limit bandwidth, connections or monthly traffic per user, run 3proxy in Docker, or fix a 3proxy.cfg that will not start.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

Builds Agent2Agent (A2A) servers and clients, the open protocol (originally from Google, now under the Linux Foundation) that lets AI agents from different frameworks call each other. Use when the user wants to create an A2A-compliant agent, build an Agent Card, implement task management, connect agents across frameworks, set up agent discovery, handle streaming responses, implement push notifications, or orchestrate multi-agent workflows. Trigger words: a2a, agent to agent, agent2agent, a2a protocol, a2a server, a2a client, agent card, agent interoperability, agent collaboration, multi-agent, agent discovery, a2a sdk, a2a task.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

Plans a controlled experiment (A/B test) so its result can be trusted: writes the hypothesis, picks one primary metric and the guardrails, computes sample size and run time, specifies how visitors are assigned and when exposure is logged, and reads out the result with a confidence interval. Use when someone says "set up an A/B test", "split test this page", "how many visitors do I need", "how long should the experiment run", "is this result significant", "can I stop the test early", or wants to test a headline, price, layout or onboarding change against the current version.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

ably

免费

Ably is a hosted realtime messaging service: clients publish and subscribe to named channels over WebSockets, see who is present, replay message history, and resume after a dropped connection. Use when a user asks to "add realtime updates", "push live notifications to the browser", "show who is online", "add a chat room with typing indicators", "publish from a serverless function", or "authenticate Ably clients without exposing the API key". Covers the ably 2.x JavaScript SDK (Realtime and REST), JWT token authentication, presence, history and rewind, batch publishing, and the @ably/chat 1.x SDK.

中文简介正在准备中。当前显示原文说明。

TerminalSkills/skills1722026年10月14日 更新

查看 TerminalSkills 的全部技能

报告此技能的问题