Request/Response wrapper for AWS Lambda with API Gateway
Project description
AWS Lambda Requests Wrapper
Request/Response wrapper for AWS Lambda with API Gateway.
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
Built Distribution
Close
Hashes for aws-lambda-requests-wrapper-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | abd2c655f7a552eadb80825e85e7ee5fda69d4749bf76e3505f8b8adcd354141 |
|
MD5 | c0733c446a09b21d91cd0c9622293f7e |
|
BLAKE2b-256 | ddab1d6e007556ca31efc8b5015a01cac362c95c0dc7caacda8d371167aabbc7 |
Close
Hashes for aws_lambda_requests_wrapper-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1946fbb6d6a95a7361d77b1e2092d1440a412f633f874197ebf3771ad867e4a5 |
|
MD5 | 58c9c12f18dae0e3a8444c93355a0801 |
|
BLAKE2b-256 | 79d15f82bf8dbeed56aa741ca68b9e3d873e08f3f54af35be4753565301133a1 |