Skip to main content

Middleware to spill large responses over to S3.

Project description

ASGI S3 Response Middleware

Middleware to spill large responses over to S3.


Source Code: https://github.com/developmentseed/asgi_s3_response_middleware


Usage

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.

Example

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
)

Development

Releases

Releases are managed via CICD workflow, as described in the Python Packaging User Guide. To create a new release:

  1. Update the version in src/asgi_s3_response_middleware/__init__.py following appropriate Semantic Versioning convention.
  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asgi-s3-response-middleware-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file asgi-s3-response-middleware-0.0.1.tar.gz.

File metadata

File hashes

Hashes for asgi-s3-response-middleware-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7209db0f5f122ed5c1dbb68898e72381e6318cd101a67bf77d35e1c653291508
MD5 918e059653c0951f0f27067a816b4a20
BLAKE2b-256 860ac8894ee96e559d3e0ec7cbcb8d04b423f68575246a7f34cc213b13d604cb

See more details on using hashes here.

File details

Details for the file asgi_s3_response_middleware-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asgi_s3_response_middleware-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cf016afdd21acf247858bbc3d70de3cc055acb6de9ff025b334dbcdc27cb1a5
MD5 65bd906fb4314628e295491b815db104
BLAKE2b-256 4d6948dd00a488f9675e97bf04113196cefbcce97d1d9a28635b02b34bce53d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page