Verified SOP & TutorialAudited Score 98/100

The Complete Production SOP: How to Deploy and Run AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues in Autonomous AI Agents

Step-by-step SOP to install and run the AWS SNS-SQS Fan-Out pattern in Codex, Claude Code, and Cursor. Master filter policies, DLQs, and IaC verification.

Target Runtimes:codexclaude-codecursorwindsurf
5 min read • Updated for 2026

Technical Overview & Architectural Context

Autonomous coding agents frequently stumble when provisioning event-driven AWS architectures like the SNS-to-SQS fan-out pattern. Common failure modes include omitting the SQS queue resource policy that grants SNS 'sqs:SendMessage' permissions, misconfiguring subscription raw message delivery, and defining circular or non-existent Dead-Letter Queue (DLQ) redrive policies. Without strict constraints, agents hallucinate IAM roles instead of SQS resource policies or create subscription filter policies with invalid JSON schema structures. The 'aws-sqs-sns-fanout-pattern' skill establishes deterministic SOP boundaries for Codex, Claude Code, Cursor, and Windsurf. It enforces exact ordering: defining SNS topics and target SQS queues first, provisioning dedicated DLQ redrive policies, injecting the essential 'aws:SourceArn' condition into the SQS access policy, and establishing strict attribute-based SNS subscription filters with RawMessageDelivery flags. This prevents silent delivery failures, message drops, and non-convergent IaC rollbacks.

Prerequisites & Environment Requirements

Codex CLI/Desktop, Claude Code CLI, Cursor IDE, or Windsurf installed
AWS CLI v2 and Terraform >= 1.5.0 or AWS CDK v2 installed locally
Local workspace initialized with Git 2.40+ and valid AWS credentials configured

Verified Search Intents & Long-Tail Queries Solved

SEO Audit Score: 98/100

This operational tutorial is engineered to provide deterministic solutions for these developer search queries:

#install aws-sqs-sns-fanout-pattern in cursor ide#claude code aws-sqs-sns-fanout-pattern rules#codex desktop aws-sqs-sns-fanout-pattern setup tutorial#sns sqs fanout dead letter queue terraform cdk agent#aws-sqs-sns-fanout-pattern message filter policy automation#deterministic devops agent SOP for sns sqs fanout#aws-sqs-sns-fanout-pattern sandbox permissions and security score#how to fix aws-sqs-sns-fanout-pattern agent execution error

Step-by-Step Execution Playbook

1

Local Environment Setup & SKILL.md Mounting

Create the local skill manifest directory and inject verified procedural rules into agent runtimes.

To enable Claude Code, Codex, Cursor, or Windsurf to discover the skill, place the canonical SKILL.md file in the workspace or global agent skills path. Claude Code inspects '.claude/skills/' or project root configurations, while Cursor and Windsurf ingest skills via '.cursor/rules/' or workspace SKILL.md manifests. Mounting the skill injects triggering policies and IaC quality controls into the agent's context.

Terminal Command
mkdir -p .cursor/rules ~/.agents/skills/aws-sqs-sns-fanout-pattern && curl -fsSL https://askills.dev/api/skills/aws-sqs-sns-fanout-pattern/raw -o ~/.agents/skills/aws-sqs-sns-fanout-pattern/SKILL.md && cp ~/.agents/skills/aws-sqs-sns-fanout-pattern/SKILL.md .cursor/rules/aws-sqs-sns-fanout.mdc
SKILL.md
---
name: "aws-sqs-sns-fanout-pattern"
description: "Broadcast asynchronous events to multiple decoupled processing queues using SNS and SQS."
metadata:
  author: "AWS"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "implement sns sqs fanout"
  - "configure sqs dead letter queue"
  - "sns message filter policy"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues

Implements the SNS-SQS Fan-Out pattern: subscribing multiple SQS queues to an SNS topic, message filtering policies (attribute-based), dead-letter queue (DLQ) redrive, and KMS envelope encryption.

## Execution SOP & Rules
1. Create SNS topic and target SQS queues; declare primary and DLQ pairs before wiring subscriptions.
2. Apply SQS Queue Policy granting sns.amazonaws.com 'sqs:SendMessage' restricted to topic ARN.
3. Create SNS subscriptions with Queue ARN, RawMessageDelivery: true, and explicit FilterPolicy.
4. Set redrivePolicy on target SQS pointing to verified DLQ ARN with maxReceiveCount between 3 and 5.
Production Pro-Tip

Keep the SKILL.md body concise. Restricting the rules to exact IaC constraints saves up to 1,200 prompt tokens per inference cycle in Claude Code and Cursor.

Sandbox Gotcha

Do not grant 'shell_exec: true' or 'net_access: true' in frontmatter unless required for dry-runs. The skill only requires workspace write permissions to emit IaC definitions.

2

Environment Secrets & Dependency Validation

Ensure AWS credential environments and linter dependencies are cleanly partitioned without credential leakage.

Autonomous agents should never read raw AWS secret keys directly in LLM conversation context. Inject AWS environment variables via standard process environment or local AWS profiles. Ensure Terraform or CDK CLI tools are present so the agent can execute static validation without invoking active cloud mutations.

Terminal Command
aws sts get-caller-identity > /dev/null 2>&1 || (echo 'AWS credentials missing or expired' && exit 1)
Production Pro-Tip

Never put AWS_SECRET_ACCESS_KEY inside prompt instructions or git-tracked files; use AWS_PROFILE or short-lived federated STS session tokens.

Sandbox Gotcha

Ensure '.env*' and terraform state files (*.tfstate) are included in '.gitignore' to prevent accidental exposure during agent workspace commits.

3

Intent Matching & Trigger Invocation

Activate the skill deterministically using prompt directives that trigger frontmatter hooks.

Agent runtimes scan conversation prompts against registered skill triggers. Using precise phrasing such as 'implement sns sqs fanout' or 'sns message filter policy' forces the agent to bypass generalized multi-cloud answers and strictly execute the fan-out SOP with SQS resource policies, DLQ redrive, and message filtering.

Production Pro-Tip

Prefix prompts with explicit target constraints: 'Using aws-sqs-sns-fanout-pattern, implement sns sqs fanout for international order events with DLQ in Terraform.'

Sandbox Gotcha

Avoid ambiguous prompts like 'decouple my services with queues', which may lead the agent to hallucinate RabbitMQ or generic EventBridge code.

4

Verification, Linting & Output Quality Gate

Run structural validation and IAM/policy linter tests before committing generated architecture code.

Instruct the agent to validate the generated IaC manifests. For Terraform, execute 'terraform fmt -check' and 'terraform validate'. For AWS CDK, run 'cdk synth'. Verify that the generated SQS policy contains the 'aws:SourceArn' condition to prevent the confused deputy vulnerability.

Terminal Command
terraform validate && tflint
Production Pro-Tip

Review the generated queue policy diff to verify that 'sqs:SendMessage' is constrained strictly by 'Condition: { ArnEquals: { aws:SourceArn: <topic_arn> } }'.

Sandbox Gotcha

If 'RawMessageDelivery' is set to false, JSON message attributes used for SNS subscription filter policies will not be passed natively to SQS payloads in microservice consumer code.

Real-World Scenario: E-Commerce Checkout Order Fan-Out with International DLQ and Message Filtering

Tested Trigger Prompt (Feed directly into Codex, Claude, or Cursor):

“Implement sns sqs fanout for an order processing system. Broadcast 'OrderCreated' events to two queues: 'domestic-fulfillment-queue' and 'international-fulfillment-queue'. International orders (order_type = 'international') should route only to the international queue. Both queues must have dead-letter queues configured with maxReceiveCount of 3, RawMessageDelivery enabled, and secure queue policies restricting sender to the SNS topic ARN.”

Deterministic Agent Verification Pipeline:
Generates SNS topic 'orders-topic' with server-side KMS encryption enabled.
Creates standard SQS queues: 'domestic-fulfillment-queue', 'international-fulfillment-queue', and their DLQs: 'domestic-fulfillment-dlq', 'international-fulfillment-dlq'.
Configures redrive_policy on primary queues referencing respective DLQ ARNs with maxReceiveCount = 3.
Attaches aws_sqs_queue_policy granting 'sqs:SendMessage' to sns.amazonaws.com scoped to the SNS topic ARN via aws:SourceArn condition.
Creates aws_sns_topic_subscription with raw_message_delivery = true and filter_policy = '{"order_type": ["international"]}' on the international subscription.

Runtime Troubleshooting & Failure Modes

Error: Error: creating SNS Topic Subscription: InvalidParameter: Invalid parameter: Attributes Reason: FilterPolicy: Invalid filter policy json

Root Cause: The agent emitted the SNS subscription filter policy as a plain key-value map or malformed string instead of AWS-compliant string array structures (e.g. {"key": ["value"]}).

Resolution Command / Fix:
Ensure filter policies match AWS JSON array standards: jsonencode({"order_type": ["international"]}) instead of {"order_type": "international"}.
Error: SQS message not delivered / Silent failure: CloudWatch Metric 'NumberOfMessagesSent' shows SNS deliveries, but SQS 'ApproximateNumberOfMessagesVisible' remains 0

Root Cause: The target SQS queue is missing the required queue resource policy granting sns.amazonaws.com permission to call sqs:SendMessage, or the condition specifies an incorrect topic ARN.

Resolution Command / Fix:
aws sqs set-queue-attributes --queue-url <QUEUE_URL> --attributes '{"Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"sns.amazonaws.com\"},\"Action\":\"sqs:SendMessage\",\"Resource\":\"<QUEUE_ARN>\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"<TOPIC_ARN>\"}}}]}"}'

Frequently Asked Questions (AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues SOP)

Q:Can I use AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues across Codex, Claude Code, and Cursor simultaneously?

Yes. The skill conforms to the universal SKILL.md specification. Claude Code accesses it via '.claude/skills/' or project configs, Cursor reads it via '.cursor/rules/', and Codex/Windsurf consume it from the workspace root or global agent directory.

Q:How does AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues prevent context window overflow during long agent sessions?

By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. Agents reference targeted YAML triggers and execute focused SOP steps without unnecessary conversational bloat.

Q:Does this skill require escalated root or container permissions?

No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes with 'fs_write: workspace', 'shell_exec: false', and 'net_access: false'.

Ready to equip your autonomous agent with AWS SNS to SQS Fan-Out Messaging & Dead-Letter Queues?

Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.

Get 1-Click Install Spec