Developing extensions
Introduction
Section titled “Introduction”This section provides a brief overview of how to develop your own extensions.
Extensions API
Section titled “Extensions API”LocalStack exposes a Python API for building extensions that can be found in the core codebase in localstack.extensions.api.
The basic interface to implement is as follows:
A minimal example would look like this:
A note on importing LocalStack modules: since extensions run in the same Python process as the LocalStack runtime, you can also import other LocalStack modules outside the localstack.extensions.api module, and work with them. However, be aware that these modules are not part of our public API, and can change even with patch versions any time. Your extension may break in unexpected ways, and we cannot provide support for internal APIs.
Packaging extensions
Section titled “Packaging extensions”Your extensions needs to be packaged as a Python distribution with a setup.cfg or setup.py config. LocalStack uses the Plux code loading framework to load your code from a Python entry point. You can either use Plux to discover the entrypoints from your code when building and publishing your distribution, or manually define them as in the example below.
A minimal setup.cfg for the extension above could look like this:
The entry point group is the Plux namespace locastack.extensions, and the entry point name is the plugin name my_ready_announcer. The object reference points to the plugin class.
Using the extensions developer CLI
Section titled “Using the extensions developer CLI”The extensions CLI has a set of developer commands that allow you to create new extensions, and toggle local dev mode for extensions. Extensions that are toggled for developer mode will be mounted into the localstack container so you don’t need to re-install them every time you change something.
Creating your first extension
Section titled “Creating your first extension”Creating an extension from a template
Section titled “Creating an extension from a template”First, create a new extension from a template. To use localstack extensions dev new, you will also need to install cookiecutter via pip install cookiecutter.
LocalStack provides two extension templates to help you get started:
- Basic template (default): A minimal extension template with Python backend code
- React template: An extension template that includes a React-based UI component
Using the basic template
Section titled “Using the basic template”To create an extension using the basic template, run:
This will create a new Python project with the following layout:
- my-localstack-extension - Makefile - my_localstack_extension - extension.py
- init .py - README.md - setup.cfg - setup.py
Then run make install in the newly created project to make a distribution package.
Using the React template
Section titled “Using the React template”To create an extension with a React-based UI, use the --template react flag:
The React template provides a small app with multiple pages to demonstrate how to use multiple pages in the same extension. When you start the LocalStack container with your React-based extension enabled, the extension UI will be automatically available through the LocalStack Web Application.
- my-localstack-extension - Makefile - README.md - backend - my_localstack_extension - backend.pth - frontend - __init__.py - package.json - public - src - tsconfig.json - pyproject.toml
The extension UI will be available at http://localhost.localstack.cloud:4566/_extension/my-localstack-extension/#/dashboard when LocalStack is running.
Then run make install in the newly created project to make a distribution package.
Start LocalStack with the extension
Section titled “Start LocalStack with the extension”To start LocalStack with the extension in dev mode, first enable it by running:
Then, start LocalStack with EXTENSION_DEV_MODE=1
In the LocalStack logs you should then see something like:
Now, when you make changes to your extensions, you just need to restart LocalStack and the changes will be picked up by LocalStack automatically.
Advertise your extension
Section titled “Advertise your extension”Once your extension is ready to be used, release it on a public GitHub repository. To make your extension easily installable for everyone generate an extension badge for your extension on this page. The resulting badge should look like this:
You can create a one-click installer for your extension using our Extension Installer.