No project description provided
Project description
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
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file aws_lambda_mess-0.0.9.tar.gz
.
File metadata
- Download URL: aws_lambda_mess-0.0.9.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43d903e08793164b4f851dcfa3e825e8f1c7ecdbdec1b85a248e7246f2db63c7 |
|
MD5 | 67cd2f3055d77454de2f1ca4d3022d7c |
|
BLAKE2b-256 | ef1ec9c00169e60edab5a04f2c0b48f025b52cf9cf967499af58debad72824f7 |
File details
Details for the file aws_lambda_mess-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: aws_lambda_mess-0.0.9-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35fe6eab691099974a601813f38aeeac30d6df3cf8055636e2d68b41750fe435 |
|
MD5 | afd1c15beb8e563231140c4ca41ca295 |
|
BLAKE2b-256 | d4627d0ecb29711e6868da459032516826f7ac5581cc177b246bbb11f44cb9d8 |