Skip to main content

Lambda Gateway

pypi python pytest coverage maintainability

Test AWS Lambda functions invoked as API Gateway proxy integrations locally.

This tool extends the native Python SimpleHTTPRequestHandler to proxy requests to a local Lambda function using the ThreadingHTTPServer.

This tool is was specifically implemented to use the standard Python library only. No additional pip installation is required.

After installing, navigate to the directory where your Lambda function is defined and invoke it with the CLI tool using the configured handler, eg:

lambda-gateway [-p PORT] [-t SECONDS] lambda_function.lambda_handler
# => Serving HTTP on :: port 8000 (http://[::]:8000/) ...

Installation

Install with pip.

pip install lambda-gateway

Usage

Create a Lambda function handler in Python 3

# ./lambda_function.py
import json


def lambda_handler(event, context=None):
    # Get name from qs
    params = event.get('queryStringParameters') or {}
    name = params.get('name') or 'Pythonista'
    # Return response
    return {
        'body': json.dumps({'text': f'Hello, {name}! ~ Lambda Gateway'}),
        'statusCode': 200,
        'headers': {
            'Content-Type': 'application/json',
        },
    }

Start a local server with the signature of your Lambda handler as the argument.

Note — the handler must be importable from the current working directory

lambda-gateway [-B PATH] [-b ADDR] [-p PORT] [-t SECONDS] lambda_function.lambda_handler
# => Starting LambdaRequestHandler at http://localhost:8000/

Test the function with cURL.

curl http://localhost:8000/?name=Pythonista
# => {"text": "Hello, Pythonista! ~ Lambda Gateway"}

Timeouts

API Gateway imposes a 30 second timeout on Lambda responses. This constraint is implemented in this project using Python's async/await syntax.

The timeout length can be adjusted using the -t / --timeout CLI option.

lambda-gateway -t 3 lambda_function.lambda_handler

API Gateway Payloads

API Gateway supports two versions of proxied JSON payloads to Lambda integrations, 1.0 and 2.0.

Versions 0.8+ of Lambda Gateway use 2.0 by default, but this can be changed at startup time using the -V / --payload-version option:

lambda-gateway -V1.0 lambda_function.lambda_handler

Metadata

Release files for lambda_gateway 1.1.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 lambda_gateway 1.1.0
File Size Uploaded
lambda_gateway-1.1.0.tar.gz 13.8 kB Details

Built distribution (wheel)

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

Total release size: 22.3 kB

Release files / lambda_gateway-1.1.0.tar.gz

Download URL lambda_gateway-1.1.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b555e3ab4ef1fdc1abab084686a203e88b9dd75bc008881ef1278123377095e1
BLAKE2b-256 checksum
How to use checksums
85de5b25b512f8ca2c1389d8f857b0d1336cf343f42d22b7e279617a8fb3e61a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / lambda_gateway-1.1.0-py3-none-any.whl

Download URL lambda_gateway-1.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92ce7bae31c79e1c77ec967e78c37d8ab775ad932b0e612d212bec9abb4ca8c0
BLAKE2b-256 checksum
How to use checksums
7153d819a54593b5de862e5b3fa594bd40501060705aa722f131f5396ad695c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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