Writing Skills
writing-skills
效率与协作技能,来自 obra/superpowers,查看原文获取完整用途和操作说明。
aws-dynamodb【部署与运维】"Deploys managed NoSQL databases with DynamoDB for scalable, low-latency" key-value storage, streams, and global tables with high availability and automatic replication.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: aws-dynamodb compatibility: opencode completeness: 95 content-types:
Deploy highly scalable, serverless NoSQL databases with low-latency performance, automatic replication, and sophisticated features like streams, global tables, and transactions.
Use DynamoDB when:
Avoid DynamoDB when:
Primary Purpose: Provide fully managed, serverless NoSQL database with unlimited throughput, millisecond latency, and automatic global replication.
Common Use Cases:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
# Application Table
ApplicationDataTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: application-data
BillingMode: PROVISIONED
AttributeDefinitions:
- AttributeName: UserId
AttributeType: S
- AttributeName: Timestamp
AttributeType: N
- AttributeName: Status
AttributeType: S
KeySchema:
- AttributeName: UserId
KeyType: HASH # Partition Key
- AttributeName: Timestamp
KeyType: RANGE # Sort Key
# Provisioned throughput (initial)
ProvisionedThroughputput:
ReadCapacityUnits: 100
WriteCapacityUnits: 100
# Global Secondary Index for status queries
GlobalSecondaryIndexes:
- IndexName: StatusIndex
KeySchema:
- AttributeName: Status
KeyType: HASH
- AttributeName: Timestamp
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 50
WriteCapacityUnits: 50
# Local Secondary Index for alternative sort
LocalSecondaryIndexes:
- IndexName: UserRegionIndex
KeySchema:
- AttributeName: UserId
KeyType: HASH
- AttributeName: Status
KeyType: RANGE
Projection:
ProjectionType: ALL
# Point-in-time recovery
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
# Encryption
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DynamoDBEncryptionKey.Arn
# Time to live
TimeToLiveSpecification:
AttributeName: ExpirationTime
Enabled: true
# Streams for change capture
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
# Tags
Tags:
- Key: Application
Value: main
- Key: Environment
Value: production
# Auto-Scaling for Read Capacity
ReadAutoScalingTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 40000
MinCapacity: 100
ResourceId: !Sub 'table/${ApplicationDataTable}'
RoleARN: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable'
ScalableDimension: dynamodb:table:ReadCapacityUnits
ServiceNamespace: dynamodb
ReadScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: ddb-read-scaling
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref ReadAutoScalingTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization
ScaleOutCooldown: 60
ScaleInCooldown: 300
# Auto-Scaling for Write Capacity
WriteAutoScalingTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 40000
MinCapacity: 100
ResourceId: !Sub 'table/${ApplicationDataTable}'
RoleARN: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable'
ScalableDimension: dynamodb:table:WriteCapacityUnits
ServiceNamespace: dynamodb
WriteScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: ddb-write-scaling
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref WriteAutoScalingTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBWriteCapacityUtilization
ScaleOutCooldown: 60
ScaleInCooldown: 300
# Auto-Scaling for GSI Read Capacity
GSIReadAutoScalingTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 10000
MinCapacity: 50
ResourceId: !Sub 'table/${ApplicationDataTable}/index/StatusIndex'
RoleARN: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable'
ScalableDimension: dynamodb:index:ReadCapacityUnits
ServiceNamespace: dynamodb
GSIReadScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: ddb-gsi-read-scaling
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref GSIReadAutoScalingTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization
# KMS Encryption Key
DynamoDBEncryptionKey:
Type: AWS::KMS::Key
Properties:
Description: KMS key for DynamoDB encryption
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: 'kms:*'
Resource: '*'
- Sid: Allow DynamoDB to use the key
Effect: Allow
Principal:
Service: dynamodb.amazonaws.com
Action:
- 'kms:Decrypt'
- 'kms:GenerateDataKey'
Resource: '*'
# CloudWatch Alarms
ReadThrottleAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: DDB-Read-Throttle
MetricName: ReadThrottleEvents
Namespace: AWS/DynamoDB
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: TableName
Value: !Ref ApplicationDataTable
WriteThrottleAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: DDB-Write-Throttle
MetricName: WriteThrottleEvents
Namespace: AWS/DynamoDB
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: TableName
Value: !Ref ApplicationDataTable
UserErrorsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: DDB-User-Errors
MetricName: UserErrors
Namespace: AWS/DynamoDB
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 5
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: TableName
Value: !Ref ApplicationDataTable
Outputs:
TableName:
Value: !Ref ApplicationDataTable
Description: DynamoDB table name
TableArn:
Value: !GetAtt ApplicationDataTable.Arn
Description: DynamoDB table ARN
StreamArn:
Value: !GetAtt ApplicationDataTable.StreamArn
Description: DynamoDB Streams ARN
Key Elements:
Resources:
# Cache Table with On-Demand Billing
CacheTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: application-cache
BillingMode: PAY_PER_REQUEST # On-demand
AttributeDefinitions:
- AttributeName: CacheKey
AttributeType: S
KeySchema:
- AttributeName: CacheKey
KeyType: HASH
TimeToLiveSpecification:
AttributeName: ExpirationTime
Enabled: true
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
SSESpecification:
SSEEnabled: true
Tags:
- Key: BillingModel
Value: on-demand
Key Elements:
Resources:
# Primary Table in us-east-1
GlobalPrimaryTable:
Type: AWS::DynamoDB::GlobalTable
Properties:
GlobalTableName: user-sessions
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DynamoDBEncryptionKey.Arn
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
AttributeDefinitions:
- AttributeName: SessionId
AttributeType: S
- AttributeName: UserId
AttributeType: S
KeySchema:
- AttributeName: SessionId
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: UserIdIndex
KeySchema:
- AttributeName: UserId
KeyType: HASH
Projection:
ProjectionType: ALL
Replicas:
- Region: us-east-1
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
Tags:
- Key: Region
Value: us-east-1
- Region: eu-west-1
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
Tags:
- Key: Region
Value: eu-west-1
- Region: ap-southeast-1
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
Tags:
- Key: Region
Value: ap-southeast-1
TimeToLiveSpecification:
AttributeName: ExpirationTime
Enabled: true
Key Elements:
Lambda + DynamoDB enables:
Streams provide:
DynamoDB + Kinesis enables:
Lambda processes stream events to:
Problem: Sequential IDs as partition key causes hot partitions and throttling.
Solution:
Problem: Full table scans instead of key-value lookups waste throughput.
Solution:
Problem: Fixed provisioned capacity is wasted if traffic varies.
Solution:
Problem: Accidental deletes are permanent; no recovery option.
Solution:
Problem: Items larger than 10 KB waste throughput; poor performance.
Solution:
Problem: Uneven traffic distribution causes throttling on some partitions.
Solution:
| Category | Best Practice |
|---|---|
| Partition Key | Random/uniform distribution; no sequential keys |
| Queries | Design query patterns before schema; use indexes |
| Billing | On-demand for unpredictable; provisioned with scaling for predictable |
| Recovery | Enable PITR; test restores; TTL for automatic cleanup |
| Streams | Enable for change capture; integrate with Lambda |
| Security | KMS encryption; restricted IAM policies |
| Skill | Purpose |
|---|---|
cncf-aws-lambda | Event-driven processing on stream changes |
cncf-aws-iam | Fine-grained access control to tables |
cncf-aws-kms | Encryption key management |
cncf-aws-cloudwatch | Table monitoring and alarms |
Assess Requirements — Understand the use case, scale, integration needs, and existing infrastructure. Checkpoint: Document requirements, constraints, and success criteria.
Design Architecture — Plan component interactions, data flow, and deployment strategy using cloud-native best practices. Checkpoint: Verify the architecture addresses all requirements and follows CNCF conventions.
Implement & Configure — Create manifests, configurations, and deployment scripts. Include resource limits, health checks, and observability hooks. Checkpoint: Validate all YAML against schema and test in a staging environment.
Deploy & Monitor — Apply manifests to the cluster, verify component health, and confirm observability is working. Checkpoint: Confirm all pods/services are running, probes passing, and metrics/alerts configured.
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.