Writing Skills
writing-skills
效率与协作技能,来自 obra/superpowers,查看原文获取完整用途和操作说明。
aws-sns-reference【部署与运维】"Deploys managed pub/sub messaging with SNS for asynchronous notifications" across services, mobile push, email, and Lambda integrations.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: aws-sns-reference compatibility: opencode completeness: 95 content-types:
Deploy scalable publish-subscribe messaging for asynchronous notifications, mobile push, email delivery, and event-driven architecture.
Use SNS when:
Avoid SNS when:
Primary Purpose: Provide scalable pub/sub messaging for event notifications with multiple transport options (email, SMS, Lambda, SQS).
Common Use Cases:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
# SNS Topic
ApplicationEventsTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: application-events
DisplayName: Application Events
KmsMasterKeyId: alias/aws/sns # Encryption
Tags:
- Key: Purpose
Value: event-broadcasting
# Topic Policy
TopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
Topics:
- !Ref ApplicationEventsTopic
PolicyText:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- events.amazonaws.com
Action:
- SNS:Publish
Resource: !Ref ApplicationEventsTopic
- Effect: Deny
Principal: '*'
Action: SNS:*
Resource: !Ref ApplicationEventsTopic
Condition:
Bool:
aws:SecureTransport: 'false'
# Email Subscription
EmailSubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: email
TopicArn: !Ref ApplicationEventsTopic
Endpoint: ops-team@example.com
# SQS Queue Subscription (with dead-letter)
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: events-dlq
EventsQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: application-events
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
maxReceiveCount: 3
QueueSubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: sqs
TopicArn: !Ref ApplicationEventsTopic
Endpoint: !GetAtt EventsQueue.Arn
RawMessageDelivery: true
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
# Queue Policy to allow SNS
QueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref EventsQueue
PolicyText:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: sns.amazonaws.com
Action: sqs:SendMessage
Resource: !GetAtt EventsQueue.Arn
Condition:
ArnEquals:
aws:SourceArn: !Ref ApplicationEventsTopic
# Lambda Subscription
EventProcessorFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: event-processor
Runtime: python3.11
Handler: index.handler
Role: !GetAtt LambdaRole.Arn
Code:
ZipFile: |
import json
import logging
logger = logging.getLogger()
def handler(event, context):
logger.info(f"Received event: {json.dumps(event)}")
# Process event
return {'statusCode': 200}
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
LambdaSubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: lambda
TopicArn: !Ref ApplicationEventsTopic
Endpoint: !GetAtt EventProcessorFunction.Arn
FilterPolicy:
EventType:
- OrderCreated
- PaymentProcessed
# Permission for SNS to invoke Lambda
SNSLambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref EventProcessorFunction
Action: lambda:InvokeFunction
Principal: sns.amazonaws.com
SourceArn: !Ref ApplicationEventsTopic
# CloudWatch Alarms
MessageNotDeliveredAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: sns-message-not-delivered
MetricName: NotificationsFailed
Namespace: AWS/SNS
Statistic: Sum
Period: 300
EvaluationPeriods: 1
Threshold: 5
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: TopicName
Value: !GetAtt ApplicationEventsTopic.TopicName
Outputs:
TopicArn:
Value: !Ref ApplicationEventsTopic
Description: SNS Topic ARN
Key Elements:
Resources:
# FIFO Topic
OrderEventsTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: order-events.fifo
FifoTopic: true
ContentBasedDeduplication: false
DisplayName: Order Events
# FIFO Queue Subscription
OrderQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: order-processing.fifo
FifoQueue: true
ContentBasedDeduplication: false
VisibilityTimeout: 300
OrderQueueSubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: sqs
TopicArn: !Ref OrderEventsTopic
Endpoint: !GetAtt OrderQueue.Arn
Key Elements:
CloudWatch + SNS enables:
EventBridge + SNS enables:
SNS + SQS provides:
SNS + Lambda enables:
Problem: Failed deliveries are silently discarded.
Solution:
Problem: All subscribers receive all messages; wasted processing.
Solution:
Problem: No guarantee all messages delivered if subscribers offline.
Solution:
Problem: Messages transmitted unencrypted; data exposure risk.
Solution:
Problem: Delivery failures go undetected.
Solution:
| Category | Best Practice |
|---|---|
| Filtering | Use message attributes and filter policies |
| Reliability | Combine with SQS for persistence |
| Security | KMS encryption; restrict topic policy |
| Ordering | Use FIFO topic for ordered messages |
| Monitoring | Alarms on delivery failures; DLQ monitoring |
| Skill | Purpose |
|---|---|
cncf-aws-sqs | Persistent queuing with SNS fan-out |
cncf-aws-lambda | Lambda subscriptions and processing |
cncf-aws-cloudwatch | CloudWatch alarm notifications |
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.