Skip to main content

Request/Response wrapper for AWS Lambda with API Gateway

Project description

AWS Lambda Requests Wrapper

Request/Response wrapper for AWS Lambda with API Gateway.

Publish

Python 3.7+ PyPI - License PyPI - Version

codecov pre-commit.ci status CodeQL

Imports: isort Code style: black Checked with mypy

Install

Install and update using pip.

$ pip install -U aws-lambda-requests-wrapper

Example

Converts the lambda_handler syntax:

import json

def lambda_handler(event, context):
    ...
    response = {"key": "value"}
    return {
        "statusCode": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "body": json.dumps(response)
    }

into this:

import json

from aws_lambda_requests_wrapper.lambda_handler import lambda_request_wrapper
from aws_lambda_requests_wrapper.models import Request
from aws_lambda_requests_wrapper.models import Response

@lambda_request_wrapper()
def lambda_handler(request: Request) -> Response:
    ...
    response = {"key": "value"}
    return Response(body=json.dumps(response))

or return a Pydantic model directly:

from pydantic import BaseModel

from aws_lambda_requests_wrapper.lambda_handler import lambda_request_wrapper
from aws_lambda_requests_wrapper.models import Request

class Model(BaseModel):
    model_id: int

@lambda_request_wrapper()
def get_pydantic_model(request: Request) -> Model:
    return Model(model_id=1)

Contributing

Contributions are welcome via pull requests.

First time setup

$ git clone git@github.com:DeveloperRSquared/aws-lambda-requests-wrapper.git
$ cd aws-lambda-requests-wrapper
$ poetry install
$ source .venv/bin/activate

Tools including black, mypy etc. will run automatically if you install pre-commit using the instructions below

$ pre-commit install
$ pre-commit run --all-files

Running tests

$ poetry run pytest

Links

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

aws-lambda-requests-wrapper-0.2.3.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

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