Skip to main content

LambdaPage

Framework for serving static pages through AWS Lambda and API Gateway

Installation

Install with pip:

pip install LambdaPage

Examples

Simple examples with corresponding Serverless configuration files can be found in the examples directory

Usage

A page is composed by one or more endpoints. Each endpoint should define a REST method, a path, and a function that will handle the request with that method and path. Endpoints can also optionally specify a content-type for the response payload, this defaults to application/json (static html pages should use text/html;charset=utf-8).

Each endpoint function should accept a single argument and return a tuple with (status_code:int, response_body:str). The argument will be a Lambda-Proxy event Regardless of content-type, the response body should always be in string format. Also note that given paths are matched with incoming requests as if they were prefixes, meaning the request will be routed to the first available matching prefix. This can be confusing if you have multiple paths with similar prefixes, so be sure to always add the more specific paths first.

LambdaPage also allows for caching responses. This should primarily be done for GET requests that require several seconds to return. Currently only a S3LambdaPageCache is available, this can be added to a LambdaPage by instantiating it with a bucket and optionally a max_age for cached items (defaults to 300 seconds).

Testing

This framework provides a nice wsgi test bed powered by Falcon. Simply set up the LambdaPage and call start_local(). Note this should be done under 'main' so Lambda doesn't try to execute this code:

def hello(event):
    return 200, '{"message": "hello world"}'

if __name__ == '__main__':
    from LambdaPage import LambdaPage
    page = LambdaPage()
    page.add_endpoint(method='get', path='/', func=hello)
    page.start_local()

Then go to http://127.0.0.1:9000 in a browser.

Metadata

Release files for LambdaPage 0.0.12

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

Built distribution (wheel)

Table of built distributions (wheels) for LambdaPage 0.0.12
File Interpreter ABI Platform
LambdaPage-0.0.12-py3-none-any.whl Python 3 none any Details

Release files / LambdaPage-0.0.12-py3-none-any.whl

Download URL LambdaPage-0.0.12-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f5b270d4142fb1247e2c0832db0d9551b947b0c9c14c2e274ac990aaff4281b
BLAKE2b-256 checksum
How to use checksums
8e85de04d6e8ca982a1551a2111ee9893647eb5f1a71d47142955861d86ac1e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.2
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