Skip to main content

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.

Metadata

Release files for localfunk 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localfunk 0.0.7
File Size Uploaded Provenance
localfunk-0.0.7.tar.gz 6.7 kB Without provenance Details

Release files / localfunk-0.0.7.tar.gz

Download URL localfunk-0.0.7.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5a554510aa3e71590c561e14773e64d11c25a11d1903fa75236469f773df6808
BLAKE2b-256 checksum
How to use checksums
5a584c93ed8f2dbd8135845bc8f60d1d9d1f5fe2074f3cb1ac19dd56a0dd3ea5
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for localfunk 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page