writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
aws-sqs"Deploys managed message queues with SQS for asynchronous processing" decoupling services, and reliable message delivery with visibility timeout and dead-letter queues.
Independent GitHub snapshot · Automated classification · Original documentation governs
name: aws-sqs compatibility: opencode completeness: 95 content-types:
Deploy managed message queues for asynchronous processing with guaranteed delivery, visibility timeout, and built-in dead-letter queue support.
Use SQS when:
Avoid SQS when:
Primary Purpose: Provide reliable asynchronous message delivery with automatic scaling, deduplication, and failure handling.
Common Use Cases:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
# Dead-Letter Queue
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: processing-dlq
MessageRetentionPeriod: 1209600 # 14 days
VisibilityTimeout: 300
KmsMasterKeyId: alias/aws/sqs # Encryption
# Main Processing Queue
ProcessingQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: processing-queue
VisibilityTimeout: 300 # 5 minutes
MessageRetentionPeriod: 345600 # 4 days
ReceiveMessageWaitTimeSeconds: 10 # Long polling
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
maxReceiveCount: 3 # Move to DLQ after 3 failures
KmsMasterKeyId: alias/aws/sqs
# Queue Policy
QueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref ProcessingQueue
PolicyText:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: sns.amazonaws.com
Action: sqs:SendMessage
Resource: !GetAtt ProcessingQueue.Arn
Condition:
ArnEquals:
aws:SourceArn: arn:aws:sns:*:*:*
- Effect: Allow
Principal:
AWS: arn:aws:iam::123456789012:role/ApplicationRole
Action:
- sqs:SendMessage
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
Resource: !GetAtt ProcessingQueue.Arn
- Effect: Deny
Principal: '*'
Action: sqs:*
Resource: !GetAtt ProcessingQueue.Arn
Condition:
Bool:
aws:SecureTransport: 'false'
# Lambda Processor
ProcessorFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: queue-processor
Runtime: python3.11
Handler: index.handler
Role: !GetAtt ProcessorRole.Arn
Timeout: 300
Code:
ZipFile: |
import json
import boto3
import logging
logger = logging.getLogger()
def handler(event, context):
sqs = boto3.client('sqs')
for record in event['Records']:
try:
message_body = json.loads(record['body'])
logger.info(f"Processing: {message_body}")
# Business logic here
process_message(message_body)
# Delete on success
sqs.delete_message(
QueueUrl=record['eventSourceARN'],
ReceiptHandle=record['receiptHandle']
)
except Exception as e:
logger.error(f"Failed to process: {str(e)}")
# On error, message stays in queue for retry
raise
return {'statusCode': 200}
def process_message(message):
# Business logic
pass
ProcessorRole:
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
Policies:
- PolicyName: SQSAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
- sqs:ChangeMessageVisibility
Resource: !GetAtt ProcessingQueue.Arn
- Effect: Allow
Action:
- kms:Decrypt
Resource: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/*'
# Event Source Mapping
EventSourceMapping:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !GetAtt ProcessingQueue.Arn
FunctionName: !Ref ProcessorFunction
BatchSize: 10
MaximumBatchingWindowInSeconds: 5
FunctionResponseTypes:
- ReportBatchItemFailures
ScalingConfig:
MaximumConcurrency: 10
# CloudWatch Alarms
QueueDepthAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: sqs-queue-depth-high
MetricName: ApproximateNumberOfMessagesVisible
Namespace: AWS/SQS
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 1000
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt ProcessingQueue.QueueName
DLQDepthAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: sqs-dlq-not-empty
MetricName: ApproximateNumberOfMessagesVisible
Namespace: AWS/SQS
Statistic: Average
Period: 300
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt DeadLetterQueue.QueueName
ProcessingTimeAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: sqs-message-age-high
MetricName: ApproximateAgeOfOldestMessage
Namespace: AWS/SQS
Statistic: Maximum
Period: 300
EvaluationPeriods: 1
Threshold: 600 # 10 minutes
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt ProcessingQueue.QueueName
Outputs:
QueueUrl:
Value: !Ref ProcessingQueue
Description: Queue URL
QueueArn:
Value: !GetAtt ProcessingQueue.Arn
Description: Queue ARN
DLQUrl:
Value: !Ref DeadLetterQueue
Description: Dead-Letter Queue URL
Key Elements:
Resources:
# FIFO Queue (message order guaranteed)
OrderQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: order-processing.fifo
FifoQueue: true
ContentBasedDeduplication: false # Explicit IDs preferred
VisibilityTimeout: 300
MessageRetentionPeriod: 345600
ReceiveMessageWaitTimeSeconds: 10
DeduplicationScope: messageGroup # Dedup per group
FifoThroughputLimit: perMessageGroupId
# FIFO Dead-Letter Queue
OrderDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: order-dlq.fifo
FifoQueue: true
ContentBasedDeduplication: true
MessageRetentionPeriod: 1209600
# Link DLQ
OrderQueueWithDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: order-queue.fifo
FifoQueue: true
RedrivePolicy:
deadLetterTargetArn: !GetAtt OrderDLQ.Arn
maxReceiveCount: 3
Key Elements:
Resources:
# Batch Processing Lambda
BatchProcessorFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: batch-processor
Runtime: python3.11
Handler: index.handler
Timeout: 600 # 10 minutes for batch
Code:
ZipFile: |
import boto3
import json
from datetime import datetime, timedelta
sqs = boto3.client('sqs')
def handler(event, context):
queue_url = event['QueueUrl']
# Receive batch of messages
response = sqs.receive_message(
QueueUrl=queue_url,
MaxNumberOfMessages=10,
WaitTimeSeconds=10
)
messages = response.get('Messages', [])
try:
# Process batch
process_batch(messages)
# Delete processed messages
for msg in messages:
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=msg['ReceiptHandle']
)
except Exception as e:
# Extend visibility for slower processing
for msg in messages:
sqs.change_message_visibility(
QueueUrl=queue_url,
ReceiptHandle=msg['ReceiptHandle'],
VisibilityTimeout=600 # +10 minutes
)
raise
return {'processed': len(messages)}
def process_batch(messages):
# Batch processing logic
pass
Key Elements:
Lambda + SQS enables:
SNS + SQS enables:
ALB + SQS enables:
Problem: Messages re-delivered before processing completes; duplicates.
Solution:
Problem: Poison pill messages cause infinite retries.
Solution:
Problem: Empty responses waste API calls; high costs.
Solution:
Problem: Messages re-delivered indefinitely.
Solution:
Problem: FIFO throughput limited (300 msg/s per group).
Solution:
| Category | Best Practice |
|---|---|
| Queue Type | Standard for throughput; FIFO for order |
| Visibility | Match to processing time; adjust dynamically |
| Reliability | Dead-letter queue; batch failure reporting |
| Performance | Long polling; batch receives; 10+ messages |
| Monitoring | Queue depth; message age; DLQ depth |
| Skill | Purpose |
|---|---|
cncf-aws-sns | Fan-out to multiple queues |
cncf-aws-lambda | Event source for queue processing |
cncf-aws-cloudwatch | Queue 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.