Module for creating a simple API with AWS Lambda and API Gateway
Project description
anslapi
A python3 module for creating a simple API with AWS Lambda and API Gateway.
Install
python3 -m pip install anslapi
Configuration
Create an api gateway with the methods that are needed, and set up authentication, schemas, etc. as wished. Create a Lambda function and configure our function as the target for each method. Use Lambda proxy mode.
Usage example
from anslapi import APIHandler
def get_user(userid):
return "user.name@example.com"
def add(event):
import json
result = {
"status": "FAIL"
}
j = json.loads(event["body"])
if "userid" in j:
result["response"] = cls.get_user(j["userid"])
result["status"] = "SUCCESS"
return (200, result)
else:
result["reason"] = "Invalid request"
return (400, result)
def lambda_handler(event, context):
ah = APIHandler()
ah.add_handler('/add', 'POST', Actions.add)
response = ah.handle(event)
return response
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
anslapi-1.0.1.tar.gz
(3.2 kB
view hashes)