A flexible AWS Lambda event router with support for multiple event sources
Project description
Lambda Universal Router
A flexible and extensible AWS Lambda event router that supports multiple event sources. This library makes it easy to handle different types of AWS Lambda events in a clean and organized way.
Features
- Support for multiple AWS event sources:
- API Gateway
- SQS
- S3
- Easy to extend with new event sources
- Type-safe event handling with Python type hints
- Clean decorator-based routing
- Structured event objects with proper typing
Installation
pip install lambda-universal-router
Usage
Here's a simple example of how to use the router:
from lambda_universal_router import Router
from lambda_universal_router.events import APIGatewayEvent, SQSEvent, S3Event
router = Router()
@router.apigateway("/hello", method="GET")
def api_hello(event: APIGatewayEvent, context):
return {
"statusCode": 200,
"body": "Hello from API Gateway"
}
@router.sqs()
def process_queue(event: SQSEvent, context):
for msg in event.records:
print("SQS Message:", msg.body)
@router.s3()
def process_file(event: S3Event, context):
for record in event.records:
print("New S3 object:", record.s3.bucket.name, record.s3.object.key)
def lambda_handler(event, context):
return router.dispatch(event, context)
Event Types
API Gateway Event
The APIGatewayEvent provides access to:
- HTTP method
- Path
- Headers
- Query string parameters
- Path parameters
- Request body
- Request context
SQS Event
The SQSEvent provides access to:
- List of SQS messages
- Message attributes
- Message body
- Message ID
S3 Event
The S3Event provides access to:
- List of S3 records
- Bucket information (name, ARN)
- Object information (key, size, etag)
- Event name and time
Extending with New Event Sources
To add support for a new event source:
- Create a new event class that inherits from
BaseEvent - Create a new handler class that inherits from
EventHandler - Add the handler to the Router's
_event_handlersdictionary - Add a decorator method to the Router class
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda_universal_router-0.1.0.tar.gz.
File metadata
- Download URL: lambda_universal_router-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fd50334b656a5d3a0ec5ab3444cd89733723e0f90f4e332a08d6373b72cb41d
|
|
| MD5 |
03925c02f38cca79956b80be5c05c417
|
|
| BLAKE2b-256 |
8c522e83e06f0ccaa165d7aae93809d0a3ce3ee80e6b6f8964c7ddde32a829f5
|
File details
Details for the file lambda_universal_router-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lambda_universal_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6573411e9f868fe13c20ab58d4746164c6219bfc84ec252315b1695fa133d8e
|
|
| MD5 |
97647de94c11c8e4e7eb42287cca59e9
|
|
| BLAKE2b-256 |
e3c79c978a583af6fb9611648e35b8f452cc1c40bb53945ab362199a530fd43e
|