Skip to main content

Tools for making serverless apps easier

Project description

easy-serverless

Easy serverless is a set of tools designed to make writing serverless code easier. So far its just a wrapper for AWS Lambda functions, designed to make writing them easier and more pythonic.

Simple Example

my_function.py

def hello(first_name, last_name=""):

    message = f'Hello {first_name} {last_name}!'.strip()
    return {'message': message}

lambda_function.py

from easy_serverless.aws import easy_lambda
from my_function import hello
lambda_handler = easy_lambda(hello, unpack_lists=True)

Just point AWS to the lambda_function.lambda_handler variable (the default for Lambdas created in the console) and that's it. easy_lambda handles unpacking the arguments from the lambda event into your function so you don't have to write a bunch of boilerplate code to handle it. The following inputs to the lambda function will all work correctly.

{"first_name": "John", "last_name": "Doe"}
>>> {"message": "Hello John Doe!"}

{"first_name": "John"}
>>> {"message": "Hello John!"}

"John"
>>> {"message": "Hello John!"}

["John", "Doe"]
>>> {"message": "Hello John Doe!"}

Complex example

OK, so how does this work when you want to reuse objects between AWS Lambda invokes? We recommend the following code structure.

my_class.py

class DatabaseInterface:
    
    def __init__(self, db_engine):
        self.engine = db_engine
    
    def get(self, first_name, last_name=""):
        # code goes here
        ...

lambda_function.py

import os
from somewhere import make_engine
from easy_serverless.aws import easy_lambda
from my_function import DatabaseInterface

engine = make_engine(os.environ.get("DB_CONN_STR"))

interface = DatabaseInterface(engine)

lambda_handler = easy_lambda(interface.get, unpack_lists=True)

By keeping all object instances to lambda_function.py we have found it much easier to run tests on the code you care about, without having to mock a bunch of stuff.

Coming Soon

  • Async functions. We plan to make easy_lambda handle all the boilerplate for running Async code.
  • EasyRouter. An extension to easy_lambda to work with the AWS APIGateway integration for AWS Lambda.
  • Other languages. node is next on the list.
  • Other clouds. Azure Functions and Cloud Functions. (long way off)

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

easy_serverless-1.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_serverless-1.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file easy_serverless-1.0.1.tar.gz.

File metadata

  • Download URL: easy_serverless-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for easy_serverless-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9e92e53aa3dc75526b8d9acb0a0175dff4501dc541a12ee3b39424f8d7f992e1
MD5 6761f4b2cb8e3f3f35447fbfec083083
BLAKE2b-256 526a720d113332c6c6c72e15a2541675f36fb73e5ac4facf59baba49c36de5f9

See more details on using hashes here.

File details

Details for the file easy_serverless-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_serverless-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83c98e47b71a3923155c5151af8d1670944fa36c077e7fb045f364387d8b0733
MD5 cf37dbdfbc12181c1c740af7fb06c367
BLAKE2b-256 24581549abf240859b056d245b76f855d936c6890219ea77b2b2980ce75ae93a

See more details on using hashes here.

Supported by

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