Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yezz123/asgi-aws
Build API with ASGI in AWS Lambda with API Gateway HTTP API or REST API, or with Function URL ✨
https://github.com/yezz123/asgi-aws
api api-gateway asgi aws fastapi lambda pydantic rest-api typing
Last synced: about 1 month ago
JSON representation
Build API with ASGI in AWS Lambda with API Gateway HTTP API or REST API, or with Function URL ✨
- Host: GitHub
- URL: https://github.com/yezz123/asgi-aws
- Owner: yezz123
- License: mit
- Created: 2022-07-20T23:49:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T05:28:30.000Z (about 2 months ago)
- Last Synced: 2024-12-08T15:23:02.621Z (about 1 month ago)
- Topics: api, api-gateway, asgi, aws, fastapi, lambda, pydantic, rest-api, typing
- Language: Python
- Homepage: https://pypi.org/project/asgi_aws
- Size: 165 KB
- Stars: 27
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# asgi-aws
![logo](https://raw.githubusercontent.com/yezz123/asgi-aws/main/.github/logo.png)
Build API with ASGI in AWS Lambda with API Gateway HTTP API or REST API, or with Function URL ✨
## Installation
```sh
pip install asgi_aws
```## Example
- Create a file `main.py` with:
```python
from asgi_aws import Asgi
from typing import Optional
from fastapi import FastAPIapp = 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:
```yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31Resources:
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:
```sh
# 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:
```bash
python -m venv venv/
``````bash
source venv/bin/activate
```And then install the development dependencies:
```bash
# Install dependencies
pip install -e .[test,lint]
```### Run tests 🌝
You can run all the tests with:
```bash
bash scripts/test.sh
```### Format the code 🍂
Execute the following command to apply `pre-commit` formatting:
```bash
bash scripts/format.sh
```Execute the following command to apply `mypy` type checking:
```bash
bash scripts/lint.sh
```## License
This project is licensed under the terms of the MIT license.