Skip to main content

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


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)

Uploaded Source

Built Distribution

anslapi-1.0.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page