Skip to content

Introduction

Lynara is a tool that allows running Python ASGI applications in an AWS Lambda runtime.

When writing Lynara, we closely followed what Uvicorn does to fulfill its role as an ASGI server. However, instead of running in a long-lived loop serving many requests, Lynara receives an AWS event, passes it to the application, and stops.

Quickstart

Install Lynara:

poetry add lynara
pip install lynara

Use Lynara with your ASGI application:

app.py
import asyncio
from lynara import Lynara, APIGatewayProxyEventV2Interface
from fastapi import FastAPI

app = FastAPI()# (1)!
lynara = Lynara(app=app)

def lambda_handler(event, context):
    return asyncio.run(
        lynara.run(event, context, APIGatewayProxyEventV2Interface)
    )
  1. The app is loaded once for every cold start.

Rationale

We wanted to quickly deploy small and scalable Python applications on Lambdas. Our goal was to support small FastAPI applications with a few endpoints, but not as small as a single lambda handler. Leveraging Starlette or FastAPI in a serverless runtime was an appealing idea. Although there are existing solutions like Mangum and aws-lambda-web-adapter, they did not meet our needs.

Another aspect is being able to jump off a serverless environment as Lambdas are cheaper than Fargates and EC2s only up to a certain point. Here's a neat AWS Cost Estimator that might help you understand the costs.

What started as an evening experiment has resulted in a functional tool. Please star it on GitHub, share feedback, and follow the project if you're interested.

Others from Mirumee

  • Smyth - A tool improving the Lambda developer experience
  • Ariadne - Schema-first, Python GraphQL server
  • Ariadne Codegen - GraphQL Python code generator