Skip to main content

ASGI to AWS Lambda adapter

Project description

mangum

An attempt to provide simple AWS Lambda/API Gateway support to any ASGI application.

Work in progress.

Examples

Plain ASGI

Below is a basic ASGI application that returns a "hello world" response:

from mangum import asgi_response


class App:
    def __init__(self, scope) -> None:
        self.scope = scope

    async def __call__(self, receive, send) -> None:
        message = await receive()
        if message["type"] == "http.request":
            await send(
                {
                    "type": "http.response.start",
                    "status": 200,
                    "headers": [[b"content-type", b"text/plain"]],
                }
            )
            await send({"type": "http.response.body", "body": b"Hello, world!"})


def lambda_handler(event, context):
    return asgi_response(App, event, context)

Starlette

Here is another example, this time using Starlette, to demonstrate that the response method can be used with frameworks as well:

from mangum import asgi_response
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse

app = Starlette()

@app.route("/")
def homepage(request):
    return PlainTextResponse("Hello, world!")

def lambda_handler(event, context):
    return asgi_response(app, event, context)

Todo

  • WebSocket support through API Gateway
  • Chunked responses/streaming
  • More tests
  • Detailed instructions
  • More framework examples
  • Lots

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mangum-0.0.4.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file mangum-0.0.4.tar.gz.

File metadata

  • Download URL: mangum-0.0.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1

File hashes

Hashes for mangum-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1f6fdb1525bb347e2e1d2587af6da698641dc0cf8b87835e7e15b946847f0205
MD5 e061bdf5aef190c3072673b3dc76b9ad
BLAKE2b-256 e7ab5c5be7ef2facc1b8a55d780ac46381b729fde0cf31db6b85859d26417517

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