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.1.0.tar.gz (4.2 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.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for lambda_universal_router-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0fd50334b656a5d3a0ec5ab3444cd89733723e0f90f4e332a08d6373b72cb41d
MD5 03925c02f38cca79956b80be5c05c417
BLAKE2b-256 8c522e83e06f0ccaa165d7aae93809d0a3ce3ee80e6b6f8964c7ddde32a829f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lambda_universal_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6573411e9f868fe13c20ab58d4746164c6219bfc84ec252315b1695fa133d8e
MD5 97647de94c11c8e4e7eb42287cca59e9
BLAKE2b-256 e3c79c978a583af6fb9611648e35b8f452cc1c40bb53945ab362199a530fd43e

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