Skip to content

Latest commit

 

History

History
61 lines (39 loc) · 1.56 KB

README.rst

File metadata and controls

61 lines (39 loc) · 1.56 KB

AWSGI

AWSGI allows you to use WSGI-compatible middleware and frameworks like Flask and Django with the AWS API Gateway/Lambda proxy integration.

Replaced by an improved fork awsgi2.

Installation

awsgi2 is available from PyPI as awsgi2:

pip install awsgi2

Examples

Flask

import awsgi2
from flask import (
    Flask,
    jsonify,
)

app = Flask(__name__)


@app.route('/')
def index():
    return jsonify(status=200, message='OK')


def lambda_handler(event, context):
    return awsgi2.response(app, event, context, base64_content_types={"image/png"})

Django

import os
import awsgi2

from django.core.wsgi import get_wsgi_application

# my_app_directory/settings.py is a vanilla Django settings file, created by "django-admin startproject".
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_app_directory.settings')
# In the settings.py file, you may find it useful to include this setting to remove
# Django's need for SQLite, which is currently (2020-11-17) outdated in the Lambda runtime image
# DATABASES = { 'default': { 'ENGINE': 'django.db.backends.dummy', } }

application = get_wsgi_application()

def lambda_handler(event, context):
    return awsgi2.response(application, event, context, base64_content_types={"image/png"})