Skip to content
forked from Kludex/mangum

AWS Lambda support for ASGI applications

License

Notifications You must be signed in to change notification settings

tlaundal/mangum

Repository files navigation

Mangum

Package version Build Status

Mangum is an adapter for using ASGI applications with AWS Lambda & API Gateway.

Documentation: https://erm.github.io/mangum

Requirements

Python 3.6+

Installation

pip3 install mangum

Usage

The adapter class Mangum accepts the following optional arguments:

  • enable_lifespan : bool (default=True)

    Specify whether or not to enable lifespan support.

  • api_gateway_base_path : str (default=None)

    Base path to strip from URL when using a custom domain name.

Event and context

The AWS Lambda handler has event and context parameters. These are available in the ASGI scope object:

scope['aws.event']
scope['aws.context']

Example

from mangum import Mangum

async def app(scope, receive, send):
    await send(
        {
            "type": "http.response.start",
            "status": 200,
            "headers": [[b"content-type", b"text/plain; charset=utf-8"]],
        }
    )
    await send({"type": "http.response.body", "body": b"Hello, world!"})


handler = Mangum(app, enable_lifespan=False) # disable lifespan for raw ASGI example

WebSockets (experimental)

The adapter currently provides some basic WebSocket support using boto3 with DynamoDB. To install Mangum with the optional dependency:

pip3 install mangum[full]

About

AWS Lambda support for ASGI applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.6%
  • Shell 0.4%