Overview
This is an extremely simple framework to facilitate developing rest services running as lambda services in aws.
Features
- VERY simple
- One lambda function required to host a whole rest service
- Allows for local development
Shortcomings
- Only supports Python
- Does not support non json responses
- Query variables not supported yet
- Headers not exposed in route handlers
- Many others
Please raise issues for any enhancements or bugs.
Index
- Workflow in a nutshell
- Installing
- Create and run a new project
- Build the aws lambda zip
- Install the zip as a lambda
- Configure the api gateway
- Developer section
Workflow in a nutshell
- Install
- Create project
- Develop and test locally
- Build zip file for aws lambda
- Upload to aws
- If not done goto 3
Installing
Install the package using pip:
pip install aws_lambda_mess
After a successful installation check that the cli works:
alm --help
Create and run a new project
Create a new project using the cli:
alm new demo
This will:
- create a new directory with the name you specified
- populate the directory with some standard boilerplate
A sample app has been created for you in src\app.py
from aws_lambda_mess.framework.Route import Route
from aws_lambda_mess.framework.success import success
from aws_lambda_mess.framework.failures import bad_request
from aws_lambda_mess.framework.server import run
def index(params, body):
return success({"Hallo": "Index"})
def greet(params, body):
return success({"Hallo": params["name"]})
def default(params, body):
return bad_request()
routes = [
Route(method_pattern="GET", path_pattern="/greet/<name>", handler=greet),
Route(method_pattern=".*", path_pattern=".*", handler=default)
Route(method_pattern="GET", path_pattern="/", handler=index),
]
from aws_lambda_mess.framework.lambda_dispatcher import get_handler
lambda_handler = get_handler(routes)
if __name__ == "__main__":
run(9000, routes)
To run the app locally simply run:
python app.py
A webserver serving the above routes will spin up on port 9000
$ curl -X GET localhost:9000/
{"Hallo": "Index"}
$ curl -X GET localhost:9000/greet/somebody
{"Hallo": "somebody"}
$ curl -X GET localhost:9000/whatwhere -v
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> GET /whatwhere HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.88.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad Request
< Server: BaseHTTP/0.6 Python/3.9.13
< Date: Sun, 30 Apr 2023 06:38:25 GMT
<
* Closing connection 0
Build the aws lambda zip
To build the package to be uploaded to aws simply run:
alm build
This will create a zip file in the dist directory called package.zip
Upload this package to aws lambda either in the lambda console or via s3.
Install the zip as a lambda
Once the package has been uploaded change the handler setting under runtime settings to app.lambda_handler
Now test the package with some of these json test cases:
Test /
{
"body": "{}",
"resource": "/{proxy+}",
"path": "/",
"httpMethod": "GET",
"isBase64Encoded": true
}
Returns
{
"isBase64Encoded": false,
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Hallo\": \"Index\"}"
}
Test /greet/somebody
{
"body": "{}",
"resource": "/{proxy+}",
"path": "/greet/somebody",
"httpMethod": "GET",
"isBase64Encoded": true
}
Returns
{
"isBase64Encoded": false,
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Hallo\": \"somebody\"}"
}
Test invalid route or method
{
"body": "{}",
"resource": "/{proxy+}",
"path": "/greet/somebody",
"httpMethod": "POST",
"isBase64Encoded": true
}
{
"isBase64Encoded": false,
"statusCode": 400
}
This json gets converted to a proper http response by the proxy.
Configure the api gateway
The API gateway you attach to the lambda needs to look like this
and the methods needs to be defined to look like this:
Developer section
Run tests
???
Build aws_lambda_mess
hatch build
Upload to pip
py -m twine upload dist/* --user johanjordaan
Metadata
Release files for aws-lambda-mess 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_lambda_mess-0.0.9.tar.gz | 6.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_lambda_mess-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / aws_lambda_mess-0.0.9.tar.gz
| Download URL | aws_lambda_mess-0.0.9.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43d903e08793164b4f851dcfa3e825e8f1c7ecdbdec1b85a248e7246f2db63c7
|
|
BLAKE2b-256 checksum How to use checksums |
ef1ec9c00169e60edab5a04f2c0b48f025b52cf9cf967499af58debad72824f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / aws_lambda_mess-0.0.9-py3-none-any.whl
| Download URL | aws_lambda_mess-0.0.9-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35fe6eab691099974a601813f38aeeac30d6df3cf8055636e2d68b41750fe435
|
|
BLAKE2b-256 checksum How to use checksums |
d4627d0ecb29711e6868da459032516826f7ac5581cc177b246bbb11f44cb9d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for aws-lambda-mess 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.