SNS/SQS Cross-Account Fan-Out: Building Multi-Account Event Distribution in AWS
Learn how to implement secure cross-account event distribution using Amazon SNS and SQS. Covers IAM policies, KMS encryption, AWS CDK implementation, and common pitfalls from real-world deployments.
Abstract
Cross-account SNS/SQS fan-out enables secure event distribution across AWS account boundaries. This architecture pattern allows a single SNS topic in one account to deliver messages to multiple SQS queues in different accounts, maintaining administrative isolation while enabling event-driven communication. This guide covers the complete implementation including IAM policies, KMS encryption, AWS CDK setup, and troubleshooting common issues that emerge in production.
Why Cross-Account Fan-Out Matters
Working with multi-account AWS Organizations taught me that proper event distribution is essential for organizational scale. When you have separate accounts for different teams, services, or environments, you need a way to share events without compromising security boundaries.
The SNS/SQS fan-out pattern solves several real problems:
Administrative isolation: Each account maintains independent control over its resources. The billing team can't accidentally delete the fulfillment team's infrastructure, even though they both receive events from the same source.
Independent scaling: Consumer accounts scale their SQS processing independently. One slow consumer doesn't impact others - messages queue up in their account while others continue processing.
Cost efficiency: SNS to SQS delivery is free (you only pay for SNS publishes and SQS operations). Compared to HTTP endpoints or other integration methods, this saves significant costs at scale.
Security boundaries: Each account implements its own encryption, access policies, and compliance controls. The security team can enforce strict key management in their account without requiring changes to the publisher.
Architecture Overview
Here's how the cross-account fan-out pattern works:
The pattern requires proper configuration at three levels:
- SNS topic policy: Grants cross-account
sns:Subscribepermission - SQS queue policy: Allows SNS service principal to
sqs:SendMessage - KMS key policy (if encrypted): Permits SNS to encrypt/decrypt messages
IAM Policies and Permissions
Getting cross-account permissions right is critical. Here's what I've learned works reliably.
SNS Topic Policy (Publisher Account)
The SNS topic must explicitly grant sns:Subscribe permission to target accounts:
Key considerations:
- Use
AccountPrincipalfor organization-wide access orArnPrincipalfor specific roles - The
sns:Subscribeaction is required for creating subscriptions - This policy doesn't grant message publishing - only subscription creation
- You can add conditions to restrict by source VPC, IP range, or other factors
SQS Queue Policy (Consumer Account)
Each consumer account needs a queue policy allowing the SNS service principal to send messages:
Important details:
- The
Conditionwithaws:SourceArnprevents other SNS topics from sending to your queue rawMessageDelivery: falsewraps the message in SNS metadata (recommended for debugging)- Set
rawMessageDelivery: trueif you only want the message body without SNS envelope - Long polling (
receiveMessageWaitTime) reduces empty receives and costs
The Two-Way Handshake
Cross-account subscriptions require both accounts to agree:
- Publisher permits subscription: SNS topic policy grants
sns:Subscribeto consumer account - Consumer accepts messages: SQS queue policy allows SNS service principal to send messages
- Consumer creates subscription: Queue owner calls
sns:Subscribeusing the topic ARN
This two-way handshake is crucial. If either policy is missing, you'll get "Access Denied" errors. I've learned to always check both sides when troubleshooting subscription failures.
KMS Encryption Configuration
Encryption adds complexity to cross-account setups. AWS-managed keys don't work across account boundaries - you must use customer-managed keys.
Why AWS-Managed Keys Don't Work
When you create an SQS queue with encryption using the AWS-managed key (alias/aws/sqs), the key policy only grants permissions within that account. The SNS service in the publisher account can't use a consumer account's AWS-managed key.
Customer-Managed Key Setup
Here's a working pattern for encrypted queues:
Key policy requirements:
kms:Decrypt: SNS needs this to decrypt messages when sending to the queuekms:GenerateDataKey: Required for envelope encryptionkms:ViaServicecondition: Restricts key usage to SQS service in specific region- Enable key rotation for security best practices
Cost Consideration
Customer-managed KMS keys cost 0.03 per 10,000 requests. For cross-account scenarios, this is required - there's no free alternative.
Message Filtering for Cost Optimization
SNS subscription filters reduce costs by preventing unwanted messages from reaching queues. Filtering happens at the SNS level before SQS charges apply.
Attribute-Based Filtering
Message attributes provide simple, efficient filtering:
Payload-Based Filtering
Newer payload-based filtering (introduced in 2024) allows filtering on the message body itself:
Filter policy benefits:
- Reduces SQS request costs by 50-90% in typical scenarios
- Each subscriber receives only relevant messages
- Filter changes take up to 15 minutes to propagate
- Up to 200 filter policies per topic
FIFO Topics and Queues
FIFO (First-In-First-Out) topics provide strict ordering and exactly-once delivery. Use them when message order matters.
When to Use FIFO
FIFO makes sense for:
- Order processing workflows where sequence matters
- Financial transactions requiring exactly-once processing
- State machine transitions that must occur in order
- Inventory updates where order impacts final state
FIFO Setup Requirements
Publishing to FIFO topics:
High-throughput mode considerations:
- Default FIFO: 300 TPS with topic-level deduplication
- High-throughput mode: 30,000 TPS with message-group-level deduplication (increased January 2025)
- Cannot be reversed once enabled
- Use multiple message groups to parallelize processing
Common Pitfalls and Solutions
Here are issues I've encountered in production and their solutions.
Pitfall 1: Subscription Shows "PendingConfirmation"
Symptom: Subscription created but stuck in "PendingConfirmation" status. Messages never flow.
Root cause: When the topic owner creates the subscription (rather than the queue owner), SNS sends a confirmation message that must be manually confirmed.
Solution: Always have the queue owner create the subscription:
If you must have the topic owner create subscriptions, automate confirmation:
Pitfall 2: KMS Key Access Denied
Symptom: Messages published to SNS but never appear in encrypted SQS queue. No errors in SNS metrics.
Root cause: SNS service lacks permission to use the KMS key for encryption.
Solution: Verify KMS key policy grants SNS the required permissions:
Troubleshooting tip: Check CloudTrail logs for KMS AccessDenied errors:
Pitfall 3: Region Mismatch
Symptom: "Access Denied" errors despite correct policies.
Root cause: SNS topic and SQS queue in different regions. Cross-region direct subscriptions aren't supported for cross-account scenarios.
Solution: Keep SNS topic and SQS queues in the same region. For multi-region requirements, use SNS to Lambda forwarders:
Pitfall 4: Message Size Limits
Symptom: Some messages delivered successfully, others silently disappear.
Root cause: SNS and SQS both have 256 KB message size limits. Messages exceeding this are dropped without notification.
Solution: Keep messages under 256 KB or use S3 for large payloads:
Pitfall 5: Filter Policies Not Taking Effect
Symptom: Messages still delivered despite filter policy.
Root cause: Filter policies take up to 15 minutes to propagate, or message attributes don't match filter format.
Solution: Wait for propagation and verify attribute format:
Monitoring and Observability
Effective monitoring is essential for cross-account messaging. You need visibility into both publisher and consumer sides.
Key SNS Metrics
Key SQS Metrics
Cross-Account CloudWatch Observability
For unified monitoring across accounts, use CloudWatch Observability Access Manager:
This enables a single dashboard showing metrics from all accounts without data transfer costs (within same region).
Cost Analysis
Understanding costs helps optimize your architecture.
Pricing Breakdown (2025)
SNS costs:
- First 1 million requests/month: FREE
- Beyond free tier: $0.50 per million publishes
- SNS to SQS deliveries: FREE (major cost advantage)
SQS costs:
- First 1 million requests/month: FREE
- Standard queue: $0.40 per million requests
- FIFO queue: $0.50 per million requests
- Each 64 KB chunk = 1 request (256 KB message = 4 requests)
Fan-out cost example (1 million messages to 4 queues):
- SNS publishes: 1M × 0.50
- SNS to SQS delivery: FREE
- SQS receives: 4M × 1.60
- SQS deletes: 4M × 1.60
- Total: $3.70
With 50% message filtering:
- SNS publishes: 1M × 0.50
- Filtered deliveries: 2M messages delivered
- SQS receives: 2M × 0.80
- SQS deletes: 2M × 0.80
- Total: $2.10 (43% cost reduction)
KMS costs (for encrypted queues):
- Customer-managed key: $1/month per key
- KMS requests: $0.03 per 10,000 requests
- Each encrypted message generates 2 KMS requests
Cost Optimization Strategies
- Implement message filtering: 50-70% cost reduction in typical scenarios
- Enable SQS long polling: Reduces empty receives by 90%
- Use batch operations: Up to 10× reduction in API calls
- Keep messages under 64 KB: Avoid multi-request charges
- Use Standard queues when ordering isn't critical: 20% cheaper than FIFO
Alternative Approaches
SNS/SQS fan-out isn't always the best choice. Here are alternatives and when to consider them.
EventBridge
When to use:
- Need complex event routing (100+ rules)
- Schema registry and validation required
- Event replay capability essential
- Integration with 30+ AWS services
Trade-offs:
- 0.50)
- More powerful filtering with JSONPath-like syntax
- Built-in schema discovery and validation
- Native cross-account event buses
Kinesis Data Streams
When to use:
- Ordered stream processing required
- Need replay capability (up to 365 days)
- Multiple consumers reading at different speeds
- Real-time analytics use cases
Trade-offs:
- More expensive ($0.015 per shard hour + PUT costs)
- Complex shard management
- Better for streaming analytics than discrete events
- Higher operational overhead
Direct Lambda Invocation
When to use:
- Synchronous processing acceptable
- Event volume under Lambda concurrent execution limits
- No need for queue management
- Simple, fast processing logic
Trade-offs:
- No built-in retry queues
- Cold start considerations
- Limited by Lambda concurrency
- Less flexible than queues for scaling
Real-World Implementation Pattern
Here's a complete, production-ready multi-account setup:
Key Takeaways
Working with cross-account SNS/SQS taught me several important lessons:
Always use customer-managed KMS keys for encrypted cross-account queues. AWS-managed keys simply don't work across account boundaries. The $1/month per key is unavoidable.
Have the queue owner create subscriptions. This eliminates the manual confirmation step and reduces setup complexity. When the topic owner creates subscriptions, you need automation to handle confirmation messages.
Implement comprehensive monitoring from the start. Cross-account troubleshooting is significantly harder without proper CloudWatch metrics. Set up alarms in both publisher and consumer accounts.
Filter at the SNS level with subscription filters. This reduces costs by 50-90% in typical scenarios. Filtering happens before SQS charges apply, making it highly cost-effective.
Keep SNS topics and SQS queues in the same region. Cross-region subscriptions add significant complexity. If you need multi-region distribution, use Lambda forwarders.
DLQs must be in the subscriber account. You can't use a DLQ from the publisher account for cross-account subscriptions. Each consumer account needs its own DLQ.
Plan for 15-minute filter policy propagation. Don't expect immediate changes when updating filter policies. Test filter changes in non-production first.
The SNS/SQS fan-out pattern provides reliable, cost-effective event distribution across AWS accounts. When you need persistent queues with independent consumer scaling and strong administrative boundaries, this architecture delivers excellent results. The implementation complexity is manageable once you understand the permission model and encryption requirements.
References
- docs.aws.amazon.com - AWS documentation home (service guides and API references).
- docs.aws.amazon.com - AWS Well-Architected Framework overview.
- docs.aws.amazon.com - AWS Lambda Developer Guide.
- serverless.com - Serverless learning resources (patterns and operations).
- docs.aws.amazon.com - AWS CDK Developer Guide.
- github.com - AWS CDK source repository and release notes.
- typescriptlang.org - TypeScript Handbook and language reference.
- github.com - TypeScript project wiki (FAQ and design notes).
- owasp.org - OWASP Top 10 (common web application risks).
- martinfowler.com - Martin Fowler on software architecture (index).
- docs.aws.amazon.com - AWS Overview (official whitepaper).
- cloud.google.com - Google Cloud documentation.