This plugin invokes
Azure Functions.
It can be used in combination with other request plugins to secure, manage,
or extend the function.
Configuration Reference
This plugin is compatible with DB-less mode.
In DB-less mode, you configure Kong Gateway
declaratively.
Therefore, the Admin API is mostly read-only. The only tasks it can perform are all
related to handling the declarative config, including:
- Setting a target's health status in the load balancer
- Validating configurations against schemas
- Uploading the declarative configuration using the
/config
endpoint
Example plugin configuration
Enable on a service
Enable on a route
Enable on a consumer
Enable globally
The following examples provide some typical configurations for enabling
the azure-functions
plugin on a
service.
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
Make the following request:
curl -X POST http://localhost:8001/services/SERVICE_NAME|SERVICE_ID/plugins \
--data "name=azure-functions" \
--data "config.functionname=<AZURE_FUNCTIONNAME>" \
--data "config.appname=<AZURE_APPNAME>" \
--data "config.hostdomain=azurewebsites.net" \
--data "config.apikey=<AZURE_APIKEY>"
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: azure-functions-example
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
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_NAME|SERVICE_ID
labels:
app: SERVICE_NAME|SERVICE_ID
annotations:
konghq.com/plugins: azure-functions-example
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: SERVICE_NAME|SERVICE_ID
selector:
app: SERVICE_NAME|SERVICE_ID
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
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
.
Add this section to your declarative configuration file:
plugins:
- name: azure-functions
service: SERVICE_NAME|SERVICE_ID
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
You can configure this plugin through the Konnect UI.
From the
Service Hub, select a service version, then set up the plugin:
- In the Plugins section, click Add Plugin.
- Find and select the Azure Functions plugin.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
You can configure this plugin through the Kong Manager UI.
- In Kong Manager, select the workspace.
- From the Services section, click View for the
service row.
- From the plugin section, click Add Plugin.
- Find and select the Azure Functions plugin.
- If the option is available, select Scoped.
- Add the service name and ID to the Service field if it
is not already pre-filled.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
The following examples provide some typical configurations for enabling
the azure-functions
plugin on a
route.
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
Make the following request:
curl -X POST http://localhost:8001/routes/ROUTE_NAME|ROUTE_ID/plugins \
--data "name=azure-functions" \
--data "config.functionname=<AZURE_FUNCTIONNAME>" \
--data "config.appname=<AZURE_APPNAME>" \
--data "config.hostdomain=azurewebsites.net" \
--data "config.apikey=<AZURE_APIKEY>"
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: azure-functions-example
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
plugin: azure-functions
Then, apply it to an ingress (route or routes)
by annotating the ingress as follows:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ROUTE_NAME|ROUTE_ID
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: azure-functions-example
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
service:
name: echo
port:
number: 80
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
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
.
Add this section to your declarative configuration file:
plugins:
- name: azure-functions
route: ROUTE_NAME
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration
will target.
You can configure this plugin through the Konnect UI.
From the
Service Hub, select a service version, then set up the plugin:
- Select a route.
- In the Plugins section, click Add Plugin.
- Find and select the Azure Functions plugin.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
You can configure this plugin through the Kong Manager UI.
- In Kong Manager, select the workspace.
- Open Routes from the menu, then click View for the
route row.
- From the plugin section, click Add Plugin.
- Find and select the Azure Functions plugin.
- If the option is available, select Scoped.
- Add the route ID if it is not already prefilled.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
The following examples provide some typical configurations for enabling
the azure-functions
plugin on a
consumer.
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
Make the following request:
curl -X POST http://localhost:8001/consumers/CONSUMER_NAME|CONSUMER_ID/plugins \
--data "name=azure-functions" \
--data "config.functionname=<AZURE_FUNCTIONNAME>" \
--data "config.appname=<AZURE_APPNAME>" \
--data "config.hostdomain=azurewebsites.net" \
--data "config.apikey=<AZURE_APIKEY>"
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
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>
hostdomain: azurewebsites.net
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_NAME|CONSUMER_ID
annotations:
konghq.com/plugins: azure-functions-example
kubernetes.io/ingress.class: kong
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
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
.
Add this section to your declarative configuration file:
plugins:
- name: azure-functions
consumer: CONSUMER_NAME|CONSUMER_ID
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
Replace CONSUMER_NAME|CONSUMER_ID
with the id
or name
of the consumer that this plugin configuration will target.
You can configure this plugin through the Kong Manager UI.
- In Kong Manager, select the workspace.
- From the Consumers section, click View for the consumer row.
- Select the Plugins tab, then click Add Plugin.
- Find and select the Azure Functions plugin.
- If the option is available, select Scoped.
- Add the consumer ID if it is not already prefilled.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
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.
The following examples provide some typical configurations for enabling
the azure-functions
plugin globally.
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
Make the following request:
curl -X POST http://localhost:8001/plugins/ \
--data "name=azure-functions" \
--data "config.functionname=<AZURE_FUNCTIONNAME>" \
--data "config.appname=<AZURE_APPNAME>" \
--data "config.hostdomain=azurewebsites.net" \
--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>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
plugin: azure-functions
Add a plugins
entry in the declarative
configuration file:
plugins:
- name: azure-functions
config:
functionname: <AZURE_FUNCTIONNAME>
appname: <AZURE_APPNAME>
hostdomain: azurewebsites.net
apikey: <AZURE_APIKEY>
You can configure this plugin through the Kong Manager UI.
- In Kong Manager, select the workspace.
- Open Plugins from the menu, then click New Plugin.
- Find and select the Azure Functions plugin.
- If the option is available, set the plugin scope to Global.
-
Configure the plugin’s parameters.
You can test out the plugin with the following sample configuration:
- Config.Functionname:
<AZURE_FUNCTIONNAME>
- Config.Appname:
<AZURE_APPNAME>
- Config.Hostdomain:
azurewebsites.net
- Click Create.
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter |
Description |
name
required
Type: string |
The name of the plugin, in this case azure-functions . |
service.name or service.id
Type: string |
The name or ID of the service the plugin targets.
Set one of these parameters if adding the plugin to a service through the top-level /plugins endpoint.
Not required if using /services/SERVICE_NAME|SERVICE_ID/plugins . |
route.name or route.id
Type: string |
The name or ID of the route the plugin targets.
Set one of these parameters if adding the plugin to a route through the top-level /plugins endpoint.
Not required if using /routes/ROUTE_NAME|ROUTE_ID/plugins . |
consumer.name or consumer.id
Type: string |
The name or ID of the consumer the plugin targets.
Set one of these parameters if adding the plugin to a consumer through the top-level /plugins endpoint.
Not required if using /consumers/CONSUMER_NAME|CONSUMER_ID/plugins . |
enabled
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.functionname
required
Type: string
|
Name of the Azure function to invoke.
|
config.appname
required
Type: string
|
The Azure app name.
|
config.hostdomain
required
Type: string
Default value: azurewebsites.net
|
The domain where the function resides.
|
config.routeprefix
optional
Type: string
Default value: /api
|
Route prefix to use.
|
config.apikey
optional
Type: string
|
The apikey to access the Azure resources. If provided, it is injected as the x-functions-key header.
If keyring database encryption is enabled, this value will be encrypted.
This field is referenceable, which means it can be securely stored as a
secret
in a vault. References must follow a specific format.
|
config.clientid
optional
Type: string
|
The clientid to access the Azure resources. If provided, it is injected as the x-functions-clientid header.
If keyring database encryption is enabled, this value will be encrypted.
This field is referenceable, which means it can be securely stored as a
secret
in a vault. References must follow a specific format.
|
config.https_verify
optional
Type: boolean
Default value: false
|
Set to true to authenticate the Azure Functions server.
|
config.https
optional
Type: boolean
Default value: true
|
Use of HTTPS to connect with the Azure Functions server.
|
config.timeout
optional
Type: number
Default value: 600000
|
Timeout in milliseconds before closing a connection to the Azure Functions server.
|
config.keepalive
optional
Type: number
Default value: 60000
|
Time in milliseconds during which an idle connection to the Azure Functions server lives before being closed.
|
Note: If config.https_verify
is set as true
, then the server certificate
is 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 placeholder settings. Insert your own values
for the placeholders in the code examples:
<appname>
for the function’s app name
<functionname>
for the function name
<apikey>
for the api key
-
Test your function to make sure it works before adding it to Kong Gateway:
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 Gateway and link it to the Azure function you just created.
With a database
Without a database
Create the route:
curl -i -X POST http://localhost: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, the HTTP method, path parameters,
headers, and body are also passed to the Azure Function if provided.
curl -i -X GET http://localhost:8000/azure1?name=Kong
You should see the same result as shown in step 2:
HTTP/1.1 200 OK
...
"Hello Kong!"
Changelog
Kong Gateway 2.7.x
- Starting with Kong Gateway 2.7.0.0, if keyring encryption is enabled,
the
config.apikey
and config.clientid
parameter values will be encrypted.