π This project demonstrates how to send messages to an AWS SQS queue using FastAPI and LocalStack for local testing.
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables decoupling and scaling of microservices, distributed systems, and serverless applications. Some key benefits include:
- Scalability: Easily handle high-throughput workloads.
- Reliability: Built-in redundancy ensures message durability.
- Decoupling: Separates different parts of your application for better maintainability.
- Security: Supports encryption and access control via AWS IAM policies.
- Asynchronous Processing: Ideal for background tasks and event-driven architectures.
.
βββ .env
βββ main.py
βββ core
β βββ config.py
βββ dependencies
β βββ aws_sqs.py
βββ routes
β βββ api
β βββ messages.py
βββ schemas
β βββ messages.py
βββ utils
βββ logger.py
- Python 3.8+
- uv (for dependency management)
1οΈβ£ Clone the repository:
git clone https://github.com/egoan82/fastapi-with-aws-sqs.git
cd fastapi-with-aws-sqs2οΈβ£ Create and activate a virtual environment with uv:
uv venv
source .venv/bin/activate3οΈβ£ Install dependencies:
pip install -r requirements.txt4οΈβ£ Configure environment variables in .env:
AWS_KEY_ID="test"
AWS_SECRET_KEY="test"
AWS_REGION="us-east-1"
SQS_QUEUE_URL="https://localhost.localstack.cloud:4566/000000000000/queue.fifo"
LOCALSTACK_URL="https://localhost.localstack.cloud:4566"1οΈβ£Β Run the FastAPI application:
uvicorn main:app --reloadοΈ2οΈβ£ Run listener to receive messages:
python main.py3οΈβ£ Access the interactive API documentation:
π Swagger UI
π ReDoc
1οΈβ£ Make a POST request to /send_message with the following body:
{
"title": "string",
"message": "string"
}2οΈβ£ The API responds with the message_id of the sent message.
Here are some screenshots of the API in action:
π Happy coding and enjoy building with FastAPI and AWS SQS! π




