This documentation provides a complete walkthrough of building and running a demo for Amazon SQS Fair Queues using Python, AWS Free Tier, and the Boto3 SDK. The goal of this project is to demonstrate how Fair Queues automatically ensure message delivery fairness among tenants without requiring application-level throttling or prioritization logic.
-
Introduction to SQS Fair Queues
-
Prerequisites
-
AWS Setup
- IAM User Creation
- Access Key and Secret Key
-
Creating the SQS Fair Queue
-
Local Environment Setup
- Cloning the Repository
- Installing Python Requirements
-
Understanding the Folder Structure
-
Code Explanation
- Producer Script (
producer.py) - Consumer Script (
consumer.py)
- Producer Script (
-
Why Two Terminals Are Used
-
Running the Demo
-
Observing Results in AWS Console
-
Cleanup Steps and Security Best Practices
-
Conclusion
Amazon SQS Fair Queues provide a new queue type that balances message consumption from different tenants or sources. Instead of relying on application logic to prevent noisy tenants from dominating the queue, Fair Queues apply adaptive rate-limiting and deliver messages fairly.
Before starting the project, ensure you have the following:
- An AWS Free Tier account
- Python 3.8 or later
- AWS CLI installed and configured
- Git installed on your system
- A GitHub repository (e.g., https://github.com/Ismail-k13/aws-sqs-fair-queue-demo.git)
You need to create an IAM user to interact with AWS services securely.
-
Go to the AWS IAM Console
-
Click on "Users" > "Add user"
-
Enter a username (e.g.,
sqs-fair-demo-user) -
Enable "Programmatic access"
-
Attach policies:
AmazonSQSFullAccess
-
Create the user and save the Access Key ID and Secret Access Key securely
These keys authenticate your local Python scripts with AWS to send/receive messages via the SQS service using the Boto3 SDK.
- Go to the Amazon SQS Console
- Click "Create Queue"
- Select "Fair Queue"
- Name the queue:
FairQueueDemo - Region:
eu-north-1(Stockholm) to stay within Free Tier - Click "Create Queue"
git clone https://github.com/Ismail-k13/aws-sqs-fair-queue-demo.git
cd aws-sqs-fair-queue-demopip install boto3Add this to a file named requirements.txt if not already present:
boto3
aws-sqs-fair-queue-demo/
├── scripts/
│ ├── producer.py # Sends messages from tenants
│ └── consumer.py # Consumes and processes messages
├── assets/
│ └── screenshots/ # Optional visuals for queue setup and metrics
├── .gitignore
├── README.md
├── LICENSE
└── requirements.txt
This script simulates sending messages from multiple tenants: TenantA, TenantB, and TenantC. TenantB sends more messages to simulate a noisy tenant.
It uses the MessageAttributes field to label each message with its tenant.
Command to run:
python scripts/producer.pyThis script polls the queue continuously and prints the messages it receives. It demonstrates how Fair Queues ensure fairness by balancing message delivery from each tenant.
Command to run:
python scripts/consumer.pyUsing separate terminals for producer and consumer scripts allows parallel simulation:
- One terminal runs
producer.pyto continuously send messages - Another runs
consumer.pyto poll and process messages
This setup helps observe real-time fairness behavior, especially when one tenant is sending more messages.
- Open Terminal 1:
python scripts/producer.py- Open Terminal 2:
python scripts/consumer.pyExpected Output:
- Messages from all tenants get processed in a balanced way
TenantB(noisy sender) does not dominate delivery order
-
Navigate to your
FairQueueDemo -
Go to the Monitoring tab
-
Observe metrics:
NumberOfMessagesSentNumberOfMessagesReceivedApproximateAgeOfOldestMessage
These help validate that the queue is processing messages fairly and not getting backlogged.
To avoid unnecessary charges:
- Go to the SQS Console
- Select
FairQueueDemo - Choose "Delete"
If created solely for this demo:
- Go to the IAM Console
- Find the user
- Click "Delete User"
Removing access keys and queues ensures there are no lingering resources that could be misused or cause cost.
This demo project demonstrates how Amazon SQS Fair Queues can be used to create a fair and balanced message delivery system without modifying application-level logic. It is ideal for multi-tenant applications where one tenant may send more messages than others. Using AWS Free Tier, IAM, Boto3, and simple Python scripts, developers can simulate and observe the benefits of this new queue type in real time.