Skip to main content

No project description provided

Project description

EasyLambda

A lightweight, FastAPI-inspired framework for building AWS Lambda functions with Python.

Installation

You can install the library using pip:

pip install leandropls.easylambda

The library is also available as AWS Lambda Layers (choose based on your Python version and architecture):

  • arn:aws:lambda:us-east-2:144273415340:layer:easylambda-0_1_3-python3_11-arm64:1
  • arn:aws:lambda:us-east-2:144273415340:layer:easylambda-0_1_3-python3_11-x86_64:1
  • arn:aws:lambda:us-east-2:144273415340:layer:easylambda-0_1_3-python3_12-arm64:1
  • arn:aws:lambda:us-east-2:144273415340:layer:easylambda-0_1_3-python3_12-x86_64:1

Requirements:

  • Python 3.11 or 3.12
  • AWS Lambda arm64 or x86_64 architecture (when using as a Lambda Layer)
  • Region: us-east-2 (when using as a Lambda Layer)

Quick Start

from leandropls.easylambda import get

@get("/")
def lambda_handler() -> dict:
    return {"message": "Hello World!"}

Features

Request Parameters

EasyLambda supports various ways to handle request parameters:

Path Parameters

from typing import Annotated
from leandropls.easylambda import get
from leandropls.easylambda.path import Path

@get("/items/{item_id}")
def lambda_handler(item_id: Annotated[int, Path("item_id")]) -> dict:
    return {"item_id": item_id}

Query Parameters

from typing import Annotated
from leandropls.easylambda import get
from leandropls.easylambda.query import Query

items = [
    {"item_name": "Foo"},
    {"item_name": "Bar"},
    {"item_name": "Baz"},
]


@get("/items")
def lambda_handler(
    skip: Annotated[int, Query("skip")] = 0,
    limit: Annotated[int, Query("limit")] = 10,
) -> list[dict]:
    return items[skip : skip + limit]

Request Body

from typing import Annotated
from leandropls.easylambda import post
from leandropls.easylambda.body import Body
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    description: str | None = None
    price: float
    tax: float | None = None

@post("/items")
def lambda_handler(item: Annotated[Item, Body]) -> dict:
    return item.model_dump()

Headers

from typing import Annotated
from leandropls.easylambda import get
from leandropls.easylambda.header import Header

@get("/items")
def lambda_handler(
    user_agent: Annotated[str | None, Header("user-agent")] = None,
) -> dict:
    return {"User-Agent": user_agent}

Response Handling

EasyLambda provides flexible response handling options:

Dictionary Response

The simplest way to return a response:

from leandropls.easylambda import get

@get("/")
def lambda_handler() -> dict:
    return {"message": "Hello World!"}

Pydantic Model Response

For type-safe responses:

from leandropls.easylambda import get
from pydantic import BaseModel

class HandlerResponse(BaseModel):
    message: str

@get("/")
def lambda_handler() -> HandlerResponse:
    return HandlerResponse(message="Hello World!")

Custom Response

For full control over the response:

from leandropls.easylambda import get
from leandropls.easylambda.aws import Response

@get("/")
def lambda_handler() -> Response:
    return Response(
        statusCode=418,
        body="I'm a teapot",
    )

Key Features

  • FastAPI-inspired syntax
  • Type hints and validation using Pydantic
  • Support for path parameters, query parameters, request body, and headers
  • Flexible response handling
  • Lightweight and optimized for AWS Lambda environment
  • No heavy web framework dependencies

Best Practices

  1. Use type hints consistently for better code clarity and automatic validation
  2. Leverage Pydantic models for request/response validation
  3. Keep functions focused and single-purpose
  4. Use meaningful parameter names that match your API design
  5. Provide default values for optional parameters

Limitations

  • When using as a Lambda Layer:
    • Only available in us-east-2 region
    • Requires Python 3.11 or 3.12
    • Must be used as a Lambda Layer

Contributing

The project is available on GitHub at: https://github.com/leandropls/easylambda

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

leandropls_easylambda-0.1.3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

leandropls_easylambda-0.1.3-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file leandropls_easylambda-0.1.3.tar.gz.

File metadata

  • Download URL: leandropls_easylambda-0.1.3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.4.0

File hashes

Hashes for leandropls_easylambda-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bf0be0712f2658b88b2e1dc7077f7cd68148de9bb96989a8546e8032a6cf9f70
MD5 e593265ebf029cc78ba6060d24287f4d
BLAKE2b-256 d2531afd13c8248d3587bb033c018a967f590eb76ca1aa0b5d3b61af44788843

See more details on using hashes here.

File details

Details for the file leandropls_easylambda-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for leandropls_easylambda-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f97e0ac25c5597dffc76e7a5a41f062d0476ac62d63c57c6ad41b4393ea17708
MD5 955fed3f664099ac5d2d6e331a7cff45
BLAKE2b-256 5e97fb8364a9d7d938c9726803c9cd81d95e5313226316ea4032bfd1f4ca5298

See more details on using hashes here.

Supported by

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