All Projects โ†’ HDE โ†’ Python Lambda Local

HDE / Python Lambda Local

Licence: mit
Run AWS Lambda function on local machine

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python Lambda Local

Bitwarden Serverless
Implementation of the Bitwarden API using an AWS serverless stack
Stars: โœญ 217 (-13.55%)
Mutual labels:  aws-lambda
Serverless Chrome
๐ŸŒ Run headless Chrome/Chromium on AWS Lambda
Stars: โœญ 2,625 (+945.82%)
Mutual labels:  aws-lambda
Serverless Prune Plugin
Serverless plugin to reap unused versions of deployed functions from AWS
Stars: โœญ 243 (-3.19%)
Mutual labels:  aws-lambda
Pychromeless
Python Lambda Chrome Automation (naming pending)
Stars: โœญ 219 (-12.75%)
Mutual labels:  aws-lambda
Aws Lambda Cheatsheet
AWS Lambda cheatsheet.
Stars: โœญ 227 (-9.56%)
Mutual labels:  aws-lambda
Aws Lambda Typescript
This sample uses the Serverless Application Framework to implement an AWS Lambda function in TypeScript, deploy it via CloudFormation, publish it through API Gateway to a custom domain registered on Route53, and document it with Swagger.
Stars: โœญ 228 (-9.16%)
Mutual labels:  aws-lambda
Chrome Aws Lambda Layer
43 MB Google Chrome to fit inside AWS Lambda Layer compressed with Brotli
Stars: โœญ 212 (-15.54%)
Mutual labels:  aws-lambda
Lambdium
headless chrome + selenium webdriver in AWS Lambda using the serverless application model
Stars: โœญ 246 (-1.99%)
Mutual labels:  aws-lambda
Django web ansible
่‡ชๅŠจๅŒ–่ฟ็ปด็ฎก็†็ณป็ปŸ
Stars: โœญ 227 (-9.56%)
Mutual labels:  virtualenv
Nuxt Serverless
Nuxt.js Serverless SSR Starter on AWS (Lambda + API Gateway + S3) with Serverless Framework
Stars: โœญ 235 (-6.37%)
Mutual labels:  aws-lambda
Ffmpeg Aws Lambda Layer
FFmpeg/FFprobe AWS Lambda layer
Stars: โœญ 222 (-11.55%)
Mutual labels:  aws-lambda
Aws Lambda Haskell Runtime
โšกHaskell runtime for AWS Lambda
Stars: โœญ 223 (-11.16%)
Mutual labels:  aws-lambda
Formplug Serverless
Form forwarding service for AWS Lambda
Stars: โœญ 232 (-7.57%)
Mutual labels:  aws-lambda
Apilogs
Easy logging and debugging for Amazon API Gateway and AWS Lambda Serverless APIs
Stars: โœญ 216 (-13.94%)
Mutual labels:  aws-lambda
Lumigo Cli
Open source CLI tool to help you develop and manage serverless applications.
Stars: โœญ 242 (-3.59%)
Mutual labels:  aws-lambda
Hal
hal provides an AWS Lambda Custom Runtime environment for your Haskell applications.
Stars: โœญ 213 (-15.14%)
Mutual labels:  aws-lambda
Algnhsa
AWS Lambda Go net/http server adapter
Stars: โœญ 226 (-9.96%)
Mutual labels:  aws-lambda
Serverless Puppeteer Layers
Serverless Framework + AWS Lambda Layers + Puppeteer = โค๏ธ
Stars: โœญ 247 (-1.59%)
Mutual labels:  aws-lambda
Aws Extensions For Dotnet Cli
Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
Stars: โœญ 242 (-3.59%)
Mutual labels:  aws-lambda
Lambda Tester
Helper for unit testing AWS Lambda functions
Stars: โœญ 233 (-7.17%)
Mutual labels:  aws-lambda

python-lambda-local

Join the chat at https://gitter.im/HDE/python-lambda-local wercker status PyPI version

Run lambda function on local machine

Prepare development environment

Please use a newly created virtualenv of Python 3.7+.

Installation

Within virtualenv, run the following command.

$ pip install python-lambda-local

This will install the package with name python-lambda-local in the virtualenv. Now you can use the command python-lambda-local to run your AWS Lambda function written in Python on your own machine.

Usage as a shell command

Run python-lambda-local -h to see the help.

usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
                           [-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]
                           [-e ENVIRONMENT_VARIABLES] [--version]
                           FILE EVENT

Run AWS Lambda function written in Python on local machine.

positional arguments:
  FILE                  lambda function file name
  EVENT                 event data file name

optional arguments:
  -h, --help            show this help message and exit
  -l LIBRARY_PATH, --library LIBRARY_PATH
                        path of 3rd party libraries
  -f HANDLER_FUNCTION, --function HANDLER_FUNCTION
                        lambda function handler name, default: "handler"
  -t TIMEOUT, --timeout TIMEOUT
                        seconds until lambda function timeout, default: 3
  -a ARN_STRING, --arn-string ARN_STRING
                        ARN string for lambda function
  -v VERSION_NAME, --version-name VERSION_NAME
                        lambda function version name
  -e ENVIRONMENT_VARIABLES, --environment-variables ENVIRONMENT_VARIABLES
                        path to flat json file with environment variables
  --version             print the version of python-lambda-local and exit

Prepare development directory

Project directory structure

Suppose your project directory is like this:

โ”œโ”€โ”€ event.json
โ”œโ”€โ”€ lib
โ”‚   โ”œโ”€โ”€ rx
โ”‚   โ”‚   โ”œโ”€โ”€ abstractobserver.py
โ”‚   โ”‚   โ”œโ”€โ”€ ... (package content of rx)
...
โ”‚   โ”‚       โ””โ”€โ”€ testscheduler.py
โ”‚   โ””โ”€โ”€ Rx-1.6.1.dist-info
โ”‚       โ”œโ”€โ”€ DESCRIPTION.rst
โ”‚       โ”œโ”€โ”€ METADATA
โ”‚       โ”œโ”€โ”€ metadata.json
โ”‚       โ”œโ”€โ”€ pbr.json
โ”‚       โ”œโ”€โ”€ RECORD
โ”‚       โ”œโ”€โ”€ top_level.txt
โ”‚       โ”œโ”€โ”€ WHEEL
โ”‚       โ””โ”€โ”€ zip-safe
โ””โ”€โ”€ test.py

The handler's code is in test.py and the function name of the handler is handler. The source depends on 3rd party library rx and it is installed in the directory lib. The test event in json format is in event.json file.

Content of test.py:

from __future__ import print_function
from rx import Observable


def handler(event, context):
    xs = Observable.from_(range(event['answer']))
    ys = xs.to_blocking()
    zs = (x*x for x in ys if x % 7 == 0)
    for x in zs:
        print(x)

Content of event.json:

{
  "answer": 42
}

Run the lambda function

Within the project root directory, you can run the lambda function with the following command

python-lambda-local -l lib/ -f handler -t 5 test.py event.json

The output will be like:

[root - INFO - 2018-11-20 17:10:53,352] Event: {'answer': 42}
[root - INFO - 2018-11-20 17:10:53,352] START RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531 Version: 
0
49
196
441
784
1225
[root - INFO - 2018-11-20 17:10:53,359] END RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531
[root - INFO - 2018-11-20 17:10:53,360] REPORT RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531	Duration: 2.17 ms
[root - INFO - 2018-11-20 17:10:53,360] RESULT:
None

Usage as a library

API signature

call(func, event, context, environment_variables={})

Call a handler function func with given event, context and custom environment_variables.

Sample

  1. Make sure the 3rd party libraries used in the AWS Lambda function can be imported.
pip install rx==1.6.1
  1. To call the lambda function above with your python code:
from lambda_local.main import call
from lambda_local.context import Context

import test

event = {
    "answer": 42
}
context = Context(5)

call(test.handler, event, context)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].