Skip to main content

asgi-aws

logo

Test

Build API with ASGI in AWS Lambda with API Gateway HTTP API or REST API, or with Function URL ✨

Installation

pip install asgi_aws

Example

  • Create a file main.py with:
from asgi_aws import Asgi
from typing import Optional
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}

entry_point = Asgi.entry_point(app)

Deploy it

  • Let's create for example a yaml file with the following content:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  ExFunctionUrlAPI:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.10
      CodeUri: src/
      Handler: main.entry_point
      MemorySize: 256
      Timeout: 30
      FunctionUrlConfig:
        AuthType: NONE
  • Now, we can deploy the function with the following command:
# deploy HTTP API
sam build -t api.yaml --use-container
sam run deploy

Note: You can also deploy the function under Deployment for Rest API or with a Function URL.

Development 🚧

Setup environment 📦

You should create a virtual environment and activate it:

python -m venv venv/
source venv/bin/activate

And then install the development dependencies:

# Install dependencies
pip install -e .[test,lint]

Run tests 🌝

You can run all the tests with:

bash scripts/test.sh

Format the code 🍂

Execute the following command to apply pre-commit formatting:

bash scripts/format.sh

Execute the following command to apply mypy type checking:

bash scripts/lint.sh

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for asgi-aws 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asgi-aws 2.0.0
File Size Uploaded
asgi_aws-2.0.0.tar.gz 71.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asgi-aws 2.0.0
File Interpreter ABI Platform
asgi_aws-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 78.8 kB

Release files / asgi_aws-2.0.0.tar.gz

Download URL asgi_aws-2.0.0.tar.gz
Size 71.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3cf645efbcb4362361b637dde484e6331899cdff4f10934c5beceedcd0508577
BLAKE2b-256 checksum
How to use checksums
416a4e10fa76eaf635fc5cc1987ec7d530c0e5dd666d0e65df9736cb5c3f5535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / asgi_aws-2.0.0-py3-none-any.whl

Download URL asgi_aws-2.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69a3a924cf70b07cbf4d6f37e5f558b29b58ce47a976b9bd9387dec16bc9e65c
BLAKE2b-256 checksum
How to use checksums
82d4d04cae57cd3e3aaa44a116685e214a94ded6da1ba4f4e5bdc52acfb97a1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page