Lambda Universal Router
A flexible and type-safe router for AWS Lambda functions that supports multiple event sources.
Quick Start
pip install lambda-universal-router
Basic Usage
from lambda_universal_router import Router
from lambda_universal_router.events import APIGatewayEvent, SQSEvent
router = Router()
@router.apigateway("/hello", method="GET")
def hello(event: APIGatewayEvent, context):
name = event.query_string_parameters.get('name', 'World')
return {
"statusCode": 200,
"body": f"Hello, {name}!"
}
@router.sqs()
def process_queue(event: SQSEvent, context):
for msg in event.records:
print(f"Processing message {msg.message_id}: {msg.body}")
def lambda_handler(event, context):
return router.dispatch(event, context)
Features
- 🎯 Type-safe event handling with proper Python type hints
- 🔄 Support for multiple AWS event sources
- 🎨 Clean decorator-based routing
- 📦 Easy to extend with new event sources
- 🔒 Structured event objects with proper typing
- 🔍 Custom event handler support for unknown event types
Event Sources
- API Gateway - Handle REST and HTTP API requests
- SQS - Process messages from queues
- S3 - React to object changes
- DynamoDB Streams - Handle table changes
- Kinesis - Process data streams
- SNS - Handle notifications
- EventBridge - Handle scheduled and custom events
- Custom Events - Handle unknown event types
Documentation
Links
License
This project is licensed under the MIT License - see the LICENSE file for details.