Skip to main content

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:

  1. Create a new event class that inherits from BaseEvent
  2. Create a new handler class that inherits from EventHandler
  3. Add the handler to the Router's _event_handlers dictionary
  4. 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

lambda_universal_router-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lambda_universal_router-0.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file lambda_universal_router-0.2.0.tar.gz.

File metadata

  • Download URL: lambda_universal_router-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for lambda_universal_router-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ed505e84a9cdd950950b9bbe0bd7da9780819e7745197c40d89a24c425a2c97c
MD5 1603155d01cc5b9e1fb6de6af37c1b73
BLAKE2b-256 08c5fdce1ad774d1dad14b4a5152bfb0bd34221ff5920a68e7e261014d1ca1a2

See more details on using hashes here.

File details

Details for the file lambda_universal_router-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lambda_universal_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e223a607efd9601e132b9055f064774163471cff5745bf25cd60037221e8f63c
MD5 d9be2e69a8a26374672d6ea379966075
BLAKE2b-256 1ee9d0bf10b0400b9a273e888b4ab4fb9664311dd6fe5c90cf352f3fd1d54be4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page