Kong Functions (Pre-Plugins)

Pass Lua code as files and run in multiple phase

You can run the Pre-Function plugin in multiple phases. For example, if you want to run code in the access and header_filter phases, configure both parameters, pointing each parameter to your Lua code files or including the code directly. This example uses file syntax.

Using decK environment variables with Lua files

To pass the contents of a file to decK, pass it to an environment variable:

  1. Create your Lua script and save it in a file, for example, access-function.lua.
  2. Load the content of the Lua script into an environment variable using the following command:
    export DECK_ACCESS_FUNCTION=$(cat access-function.lua)
    

If you’re using the API, you can also pass each Lua file as a form parameter and a filename, for example:

  --form "config.access=@access-function.lua" \

Environment variables

  • ACCESS_FUNCTION: Lua code to run in the access phase.

  • HEADER_FILTER_FUNCTION: Lua code to run in the header filter phase.

Set up the plugin

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!