A libray for building backends using AWS Lambda.
- liveLambda_v2.py and you
<source_file>should be in same directory. - Import
LiveLambdaV2class fromliveLambda_v2.pyfile.
from liveLambda_v2 import LiveLambdaV2
app = LiveLambdaV2()
# Route with a single method attached to it.
@app.route("/", "GET")
def getIndex():
return {"page" : str(app.request), "route" : "GET /"}
@app.route("/", "POST")
def postIndex():
return {"page" : str(app.request), "route" : "POST /"}
# Route with url parameters.
@app.route("/user/{id}", "POST")
def routeWithParam(id):
return {"page" : str(app.request), "route" : "POST /user/{id}"}
# Route with multiple methods attached to it.
@app.route("/dynamic", ["GET", "POST", "PUT", "PATCH", "DELETE"])
def routeWithMultipleMethods():
return {"key" : str(app.request), "route" : "GET /user"}
# Your source file must containe a method which lambda runtime will invoke.
# Name of function must be same in deployment config file.
def lambda_handler(event, context):
response = app.run(event, context)
return response
-
Your source code must contain a
config.jsonfile which will contains deployment configuration and 'arn' of the role used by the AWS lambda to push the logs at AWS cloudwatch. -
Make a single
.zipfile containingliveLambda_v2.py,<your_source_code>.py, andall_libraries_you_use(files and folders).
{
"file_path": "<path_to_zip_file>",
"lambda_role_arn": "<arn>",
"function_name": "<lambda_function_name>",
"handler_function": "<source_file>.<starting_function_name>",
"api_name": "<cloudwatch_api_name>"
}
- Run
deploy.pyfile. - your
config.jsonanddeploy.pyshould be in same folder.