How to add SQS message attributes in SNS subscription?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Amazon Simple Notification Service (SNS) and Simple Queue Service (SQS) are integral components of AWS's messaging services, allowing for scalable and decoupled communication between microservices or distributed systems. SNS is a pub/sub message broker that enables applications to send time-critical messages to multiple subscribers through a "push" mechanism. SQS, on the other hand, is a queuing service designed to decouple system components by enabling asynchronous communication.
A common requirement in distributed architectures is to have SNS forward messages to an SQS queue with accompanying message attributes. This article will delineate the method and considerations for integrating SNS with an SQS queue in a way that encapsulates message attributes effectively.
Understanding SNS and SQS in Integration
When using SNS topics to notify SQS queues, one may need to include additional metadata in the form of message attributes. These attributes may contain essential information such as data type, source, priority, or any custom tag that might be useful to the consuming application.
Configuring an SNS to SQS Integration
Pre-requisites
To follow along, ensure you have:
- An AWS account with permissions to access SNS and SQS.
- The AWS CLI or AWS Management Console access.
- Basic familiarity with AWS cloud services.
Steps to Add SQS Message Attributes via SNS Subscription
1. Create an SNS Topic
To create an SNS topic:
- Using AWS Console: Navigate to the SNS dashboard and create a topic by specifying a name and other configurations as required.
- Using AWS CLI:
- Using AWS Console: Navigate to the SQS dashboard, create a new queue, and configure permissions.
- Using AWS CLI:
- SNS Console: On your topic's page, add a new subscription. Choose
SQSas the protocol and specify the queue's ARN. - AWS CLI:
- Using AWS SDK (e.g., Python's boto3):
- Using AWS SDK (e.g., Python's boto3):
- Permissions: Ensure SNS has the necessary permissions to send messages to the SQS queue. This involves setting the correct permission policy on the SQS queue.
- Attribute Limits: SNS supports up to 10 message attributes per message. Each attribute key, value, and the total byte size also have limitations. Refer to the AWS documentation for detailed quotas.
- Message Format: By default, SNS delivers messages in a JSON format that wraps the actual message and attributes. Applications consuming these messages must parse the JSON accordingly.
Related reading
- How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service
- How to allow a Kubernetes Job access to a file on host
- How to allow my user to reset their password on Cognito User Pools?
- How to append a value to list attribute on AWS DynamoDB?
- How to append a value to list attribute on AWS DynamoDB?
- How to assign a public IP to container running in AWS ECS cluster in EC2 mode
- How to assign AWS IAM Role to Service Account with Terraform?
- How to assign Elastic IP to Application Load Balancer in AWS?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.