This plugin invokes
Azure Functions.
It can be used in combination with other request plugins to secure, manage
or extend the function.
Configuration Reference
You can configure this plugin using the
Kong Admin API
or through declarative configuration, which involves directly editing
the Kong configuration file.
This plugin is compatible with requests with the following protocols:
This plugin is compatible with DB-less mode.
In DB-less mode, Kong does not have an Admin API. If using this
mode, configure the plugin using declarative configuration.
Enabling the plugin on a Service
Kong Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Service by
making the following request:
$ curl -X POST http://<admin-hostname>:8001/services/<service>/plugins \
--data "name=azure-functions" \
--data "config.functionname=AZURE_FUNCTIONNAME" \
--data "config.appname=AZURE_APPNAME" \
--data "config.apikey=AZURE_APIKEY"
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <azure-functions-example>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
plugin: azure-functions
Next, apply the KongPlugin resource to a
Service by annotating the Service as
follows:
apiVersion: v1
kind: Service
metadata:
name: <service>
labels:
app: <service>
annotations:
konghq.com/plugins: <azure-functions-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: <service>
selector:
app: <service>
Note: The KongPlugin resource only needs to be defined once
and can be applied to any Service, Consumer, or Route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a Service by
adding this section to your declarative configuration file:
plugins:
- name: azure-functions
service: <service>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
<service>
is the id
or name
of the Service that this plugin
configuration will target.
Enabling the plugin on a Route
Kong Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Route with:
$ curl -X POST http://<admin-hostname>:8001/routes/<route>/plugins \
--data "name=azure-functions" \
--data "config.functionname=AZURE_FUNCTIONNAME" \
--data "config.appname=AZURE_APPNAME" \
--data "config.apikey=AZURE_APIKEY"
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <azure-functions-example>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
plugin: azure-functions
Then, apply it to an ingress (Route or Routes)
by annotating the ingress as follows:
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: <route>
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <azure-functions-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
Note: The KongPlugin resource only needs to be defined once
and can be applied to any Service, Consumer, or Route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a Route by
adding this section to your declarative configuration file:
plugins:
- name: azure-functions
route: <route>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
<route>
is the id
or name
of the Route that this plugin configuration
will target.
Enabling the plugin on a Consumer
Kong Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a Consumer with:
$ curl -X POST http://<admin-hostname>:8001/consumers/<consumer>/plugins \
--data "name=azure-functions" \
--data "config.functionname=AZURE_FUNCTIONNAME" \
--data "config.appname=AZURE_APPNAME" \
--data "config.apikey=AZURE_APIKEY"
You can combine consumer.id
, service.id
, or route.id
in the same request, to further narrow the scope of the plugin.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <azure-functions-example>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
plugin: azure-functions
Then, apply it to a Consumer by
annotating the KongConsumer resource as follows:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: <consumer>
annotations:
konghq.com/plugins: <azure-functions-example>
kubernetes.io/ingress.class: kong
Note: The KongPlugin resource only needs to be defined once
and can be applied to any Service, Consumer, or Route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a Consumer by
adding this section to your declarative configuration file:
plugins:
- name: azure-functions
consumer: <consumer>
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
<consumer>
is the id
or username
of the Consumer that this plugin
configuration will target.
Enabling the plugin globally
A plugin which is not associated to any Service, Route, or Consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
Kong Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin globally with:
$ curl -X POST http://<admin-hostname>:8001/plugins/ \
--data "name=azure-functions" \
--data "config.functionname=AZURE_FUNCTIONNAME" \
--data "config.appname=AZURE_APPNAME" \
--data "config.apikey=AZURE_APIKEY"
Create a KongClusterPlugin
resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-azure-functions>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
plugin: azure-functions
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
plugins:
- name: azure-functions
config:
functionname: AZURE_FUNCTIONNAME
appname: AZURE_APPNAME
apikey: AZURE_APIKEY
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
name
Type: string |
The name of the plugin to use, in this case azure-functions . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
consumer.id
Type: string |
The ID of the Consumer the plugin targets. |
enabled
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.functionname
required
|
Name of the Azure function to invoke.
|
config.appname
required
|
The Azure app name.
|
config.hostdomain
optional
Default value: azurewebsites.net
|
The domain where the function resides.
|
config.routeprefix
optional
Default value: /api
|
Route prefix to use.
|
config.apikey
optional
|
The apikey to access the Azure resources. If provided, it will be injected as the x-functions-key header.
|
config.clientid
optional
|
The clientid to access the Azure resources. If provided, it will be injected as the x-functions-clientid header.
|
config.https_verify
optional
Default value: false
|
Set it to true to authenticate the Azure Functions server.
|
config.https
optional
Default value: true
|
Use of HTTPS to connect with the Azure Functions server.
|
config.timeout
optional
Default value: 600000
|
Timeout in milliseconds before aborting a connection to Azure Functions server.
|
config.keepalive
optional
Default value: 60000
|
Time in milliseconds for which an idle connection to the Azure Functions server will live before being closed.
|
Note: If config.https_verify
is set as true
, then the server certificate
will be verified according to the CA certificates specified by the
lua_ssl_trusted_certificate
directive in your Kong configuration.
Demonstration
To demonstrate the plugin, set up the Azure Functions “hello world” function.
-
In this example, we’ll consider the following settings/placeholders, insert your own values
in the placeholders:
- `<appname>` for the Functions appname
- `<functionname>` for the function name
- `<apikey>` for the api key
-
Test your function to make sure it works before adding it to Kong:
curl -i -X GET https://<appname>.azurewebsites.net/api/<functionname>?name=Kong \
-H "x-functions-key:<apikey>"
HTTP/1.1 200 OK
...
"Hello Kong!"
-
Set up a Route in Kong and link it to the Azure function you just created.
With a database
Without a database
Create the Route:
curl -i -X POST http://{kong_hostname}:8001/routes \
--data 'name=azure1' \
--data 'paths[1]=/azure1'
Add the plugin:
curl -i -X POST http://localhost:8001/routes/azure1/plugins \
--data "name=azure-functions" \
--data "config.appname=<appname>" \
--data "config.functionname=<functionname>" \
--data "config.apikey=<apikey>"
Add a Route and Plugin to the declarative config file:
routes:
- name: azure1
paths: [ "/azure1" ]
plugins:
- route: azure1
name: azure-functions
config:
appname: <appname>
functionname: <functionname>
apikey: <apikey>
Test the Azure Function through Kong
In this example, we’re only passing a query parameter name
to the Azure
Function. Besides query parameters, also the HTTP method, path parameters,
headers, and body will be passed to the Azure Function if provided.
You should see the same result as step 2 above:
curl -i -X GET http://localhost:8000/azure1?name=Kong
HTTP/1.1 200 OK
...
"Hello Kong!"