$ show logandk/serverless-wsgi
This repository is a Serverless Framework plugin that enables deploying Python WSGI applications (Flask, Django, Pyramid, etc.) to AWS Lambda via API Gateway or ALB. It automatically converts API Gateway events (v1, v2) and ALB requests into WSGI environ dictionaries, invokes the application, and transforms the response back into the appropriate Lambda proxy format. The plugin also provides a local development server (`sls wsgi serve`), automated dependency packaging from `requirements.txt`, and remote execution commands for Python code, shell commands, Django management commands, and Flask CLI commands. The codebase is split into a Node.js plugin (`index.js`) that hooks into Serverless lifecycle events (packaging, deployment, invoke local) and a set of Python modules (`serverless_wsgi.py`, `wsgi_handler.py`, `serve.py`, `requirements.py`) that handle the actual WSGI conversion, local serving, and dependency installation. The core WSGI adapter (`serverless_wsgi.py`) is a standalone, reusable library that can be used independently of the Serverless framework for any Lambda function needing to handle API Gateway events. The plugin is well-tested with both JavaScript and Python test suites, and follows a clean, modular architecture.
The LLM identified 3 files worth highlighting for reuse:
Core module that converts API Gateway/ALB events to WSGI requests and responses. Self-contained and reusable for any Lambda-based WSGI app. Handles v1, v2, ALB, and Lambda integration payloads. Demonstrates event-to-WSGI translation pattern with proper handling of headers, cookies, query strings, base64 encoding, and custom domains.
Standalone Python script to package dependencies using virtualenv and pip. Accepts multiple requirement files and pip arguments, handles blacklisting of unnecessary files (e.g., `.dist-info`, `__pycache__`), and cleans up temporary directories. Reusable for any project that needs to bundle Python packages for serverless deployment without external build tools.
Simple local development server for WSGI applications using werkzeug's built-in HTTP server. Supports threading, multiprocessing, SSL, and debug mode. Extracts the app module and callable from a dotted import path. Reusable as a lightweight development server for any WSGI app, independent of the full plugin.