Source Code: https://github.com/developmentseed/asgi-s3-response-middleware
An ASGI middleware class to automatically push repsonses S3 and instead return a 303 redirect to the object on S3.
This can be useful to avoid hitting limits on the size of API response bodies, such as when working around AWS Lambda's 6MB response limit.
import uuid
import boto3
from fastapi import FastAPI
from asgi_s3_response_middleware import S3ResponseMiddleware
s3_client = boto3.client('s3')
app = FastAPI()
app.add_middleware(
S3ResponseMiddleware,
s3_bucket_name='my-example-bucket',
s3_client=s3_client,
key_generator=lambda: f"responses/{uuid.uuid4()}",
size_threshold=2 * 1024**2, # 2MB
url_expiry=30, # 30 seconds
)
Releases are managed via CICD workflow, as described in the Python Packaging User Guide. To create a new release:
- Update the version in
src/asgi_s3_response_middleware/__init__.py
following appropriate Semantic Versioning convention. - Push a tagged commit to
main
, with the tag matching the package's new version number.
Note
This package makes use of Github's automatically generated release notes. These can be later augmented if one sees fit.