Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easier local development of Python AWS lambda functions.

NotificationsYou must be signed in to change notification settings

Valian/python-lambda-local-server

Repository files navigation

build

A Docker image to help with development of a local AWS lambda Python functions.Based on thelambci/lambda image.Created, because I haven't found an easy way to run lambda function locally.

Features:

  • Automatically installs packages from requirements.txt during startup
  • Mirrored AWS Lambda environment thanks to lambci images
  • Code is reloaded for each submitted event
  • Available simple Web UI for better workflow

Usage

Go to directory with your lambda Python code. Next, run this command:

docker run -it \  -p 8080:8080 \  -v lambda-packages-cache:/packages/ \ # if you want to persist packages cache  -v $PWD:/var/task/ \  valian/python-lambda-local-server

It should automatically install packages from your requirements.txt and start web sever written in aiohttp.To see web UI, head tohttp://localhost:8080. You should see a simple web UI for testing your lambda function.

Event UI

Assuming that you have your lambda entrypoint inlambda.py and handler is namedhandler, you shouldtype it into respective inputs. Next, add JSON body that should be passed to the function as an event, and press 'Submit event'.Result and logs should be visible on the right panel after a moment.

Example

First, clone this repository:

git clone https://github.com/Valian/python-lambda-local-servercd python-lambda-local-server

Next, start server with a proper volume mounted:

docker run -it \  -p 8080:8080 \  -v$PWD/example:/var/task/ \  valian/python-lambda-local-server

Web UI usage

Go tohttp://localhost:8080. You should see something like this:

Event UI

Specify file, handler and event and clickSubmit event.It invokes handler and prints execution logs and return value.

Api gateway tab automatically formats event to an AWS API Gateway format:API UI

Console example

You can of course usecurl to submit events. Start sever and type:

curl -XPOST localhost:8080 -d'{"event": {"url": "https://example.com"}, "file": "handler.handler"}'{"stdout": {"statusCode": 200,"url":"https://example.com/"  },"stderr":"START RequestId: b1891caf-c22b-4ce6-8639-e74862adae30 Version:$LATEST\nINFO:root:Starting request\nINFO:root:Request done, status code: 200\nEND RequestId: b1891caf-c22b-4ce6-8639-e74862adae30\nREPORT RequestId: b1891caf-c22b-4ce6-8639-e74862adae30 Duration: 803 ms Billed Duration: 900 ms Memory Size: 1536 MB Max Memory Used: 23 MB\n"}

TODO

  • Add support forServerless.yml file
  • Cleanup code, better error codes
  • Support for chaining lambda calls either through AWS SDK or API endpoint

License

MIT

About

Easier local development of Python AWS lambda functions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp