Skip to main content

Proxy Lambda functions to local code

Project description

Local Funk

What

Localfunk proxies lambda invocations to local code.

Usage

  • pipenv install --dev localfunk
  • pipenv run localfunk

Why

Serverless development leverages a lot of proprietry tools that are difficult to run locally. They can difficult to set up, and often lack features. For example Sam local start-api:

  • requires Sam build to be run on every code change, which can be very slow.
  • doesn't currently support HTTP API
  • doesn't currently support Custom Authorizers

There is a lot or effort put into trying to replicate API Gateway locally with start-api and it can be hard to keep features in sync with the deployed service.

Localfunk attempts to leverage Cloud services while still allowing local code changes to be run immediately, without a build or deploy step.

How

  • Ngrok is started locally
  • Function code is packaged that proxies invocations to local code
  • Sam deploy is run to deploy the template and the proxy function code
  • A Flask server is started locally to route events to the local code
  • The function CodeURI and environment variables are loaded to emulate the Lambda environment

Even though code is being run locally there will still need to be changes to the template e.g changing permissions and since the localfunk build process is simpler than a full Sam build, it will be quicker to get these changes deployed.

The Lambda environment variables include a session token set from the function role, by loading the environment variables locally the local code will run using the role that is defined for the function.

Possible Improvements

Run ngrok as a deamon and check for a running instance before starting a new one. Can also check template to see if ngrok has changed. This will speed up stopping and starting because there won't need to be a redeploy if it hasn't changed.

Docker-lambda is currently not integrated but adding it would bring the local invocation closer to the real Lambda environment.

Localfunk currently only works with AWS::Serverless::Function and Sam Deploy but could work with raw Cloudformation.

This library only supports calling Python local Python code but the same pattern would work for other languages. Due to the way that the code is loaded and invocated it seems simpler to run Python code from Python but maybe it would work to create a generic CLI tool that could invoke any language.

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

localfunk-0.0.4.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file localfunk-0.0.4.tar.gz.

File metadata

  • Download URL: localfunk-0.0.4.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for localfunk-0.0.4.tar.gz
Algorithm Hash digest
SHA256 08511a8228b4e1a7f75554c27e4cfd47b00388d3fe386ebf172a6374ce144766
MD5 03c66c3586efe6e5822da341893e675e
BLAKE2b-256 15bce21468207458425bfa2cf089cd703add01be09f66d5df3abd435669ccef6

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