serverless
Summary#
Name#
There are two plug-ins for serverless, namely serverless-pre-function and serverless-post-function.
The former runs at the beginning of the specified phase, while the latter runs at the end of the specified phase.
Both plug-ins receive the same parameters.
Attributes#
| Name | Type | Requirement | Default | Valid | Description |
|---|---|---|---|---|---|
| phase | string | optional | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "balancer"] | |
| functions | array[string] | required | A list of functions that are specified to run is an array type, which can contain either one function or multiple functions, executed sequentially. |
Note that only function is accepted here, not other types of Lua code. For example, anonymous functions are legal:
Closure is also legal:
But code that is not a function type is illegal:
Since v2.6, we pass the conf and ctx as the first two arguments to the servelss function, like a regular plugin.
How To Enable#
Here's an example, enable the serverless plugin on the specified route:
Test Plugin#
Use curl to access:
Then you will find the message 'serverless pre-function' and 'match uri /index.html' in the error.log, which indicates that the specified function is in effect.
Disable Plugin#
When you want to disable the serverless plugin, it is very simple, you can delete the corresponding json configuration in the plugin configuration, no need to restart the service, it will take effect immediately:
The serverless plugin has been disabled now. It works for other plugins.