FastAPI as AWS Lambda

Deploying a FastAPI app as a Lambda Function #

We can easily deploy an ASGI app, such as Django or FastAPI, as an AWG Lambda function.

To do that, we simply wrap the the ASGI app with magnum (see [0])

Note To reduce the size of the package, we must install dependencies selectively and ensure that dev. dependencies (e.g., testing, CLI tools, etc.) are excluded from the package. This helps reduce the total size of artifacts that may accumulate in the S3 bucket (when using CDK), and less obviously it can expand debugging options.

When the package size becomes too big (e.g., FastAPI with “standard” dependencies), we cannot use the web UI to look at the the source code (and test minor changes without re-uploading the whole package). But if we include only the FastAPI with core dependencies, the web UI suddenly can open the source code and allow online debugging.

Refs #