In order to give you better service we use cookies. By continuing to use our website, you agree to the use of cookies as described in our Cookie Policy

Are you a Kong Gateway user? We'd love your feedback. Take the Survey

Kong Logo
  • Get Started
  • Products
    • kong-enterprise Kong Enterprise
      • Kong Enterprise

        End-to-end connectivity platform

      • Kong Mesh

        Universal service mesh

      • Kong Studio

        Empower your developers

      • Dev Portal

        Accelerate innovation

      • Kong Manager

        Manage all your services

      • Kong Immunity

        Autonomously identify issues

      • Kong for Kubernetes

        Native Kubernetes Ingress Controller

      • Enterprise Plugins

        Instantly implement policies

      • Kong Vitals

        Monitor your Kong Enterprise

      • Get Started
    • Built on an Open-source Foundation
      • kong-gateway Kong Gateway

        API Gateway

      • kuma Kuma

        Service Mesh

      • insomnia Insomnia

        API Design and Testing

      • Install
    • Kubernetes & Subscriptions
      • Kubernetes Ingress Controller

        Ingress and CRDs

      • Subscriptions

        Kong Gateway and Enterprise features

  • Solutions
    • Use Cases
      • Decentralize Apps and Services

        Accelerate your journey into microservices

      • Secure and Govern APIs

        Empower teams to provide security, governance and compliance

      • Create a Developer Platform

        Rapidly design, publish and consume APIs and services

    • Deployment Patterns
      • API Gateway

        Take control of your microservices with the world’s most popular API gateway

      • Kubernetes

        Own your Kubernetes cluster by using Kong as an Ingress Controller

      • Service Mesh

        Build, secure and observe your modern Service Mesh

  • Plugins
  • Open Source
    • Install Kong Gateway
    • Kong Community
    • Kubernetes Ingress
    • Kuma
    • Insomnia
  • Docs
    • Documentation
      • Kong Gateway
      • Kong Enterprise
      • Kong Mesh
      • Kong Studio
      • Plugins Hub
  • Resources
    • Learning
      • eBooks
      • Webinars
      • Briefs
      • Blog
    • Community
      • Community
      • Kong Nation
      • Kong Summit
      • GitHub
    • Support
      • Enterprise Support Portal
      • FAQS
      • Kong Professional Services
      • Kong University
  • Company
    • About
    • Customers
    • Investors
    • Careers
    • Partners
    • Press
    • Contact
  • Get Started
header icon

Azure Functions

  • 1.0-x (latest)
  • 0.1-x
  • Back to Kong Plugin Hub
  • githubEdit this page
  • report-issueReport an issue
  • Configuration Reference
    • Enabling the plugin on a Service
    • Enabling the plugin on a Route
    • Enabling the plugin on a Consumer
    • Enabling the plugin globally
    • Parameters
  • Demonstration
    • Test the Azure Function through Kong
About this Plugin
Made by
Categories
  • Serverless
DB-less compatible? Yes (Kong Gateway only)
Source
  • Code
Bundled with...
    Kong Enterprise
  • 2.2.x
  • 2.1.x
  • 1.5.x
  • 1.3-x
  • 0.36-x
  • 0.35-x
    Kong Community
  • 2.2.x
  • 2.1.x
  • 2.0.x
  • 1.5.x
  • 1.4.x
  • 1.3.x
  • 1.2.x
  • 1.1.x
  • 1.0.x
  • 0.14.x

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:

  • http
  • https

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 ParameterDescription
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.

  1. 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
    
  2. 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!"
    
  3. 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!"
Thank you for your feedback.
Was this page useful?
  • Kong
    THE CLOUD CONNECTIVITY COMPANY

    Kong powers reliable digital connections across APIs, hybrid and multi-cloud environments.

    • Company
    • Customers
    • Events
    • Investors
    • Careers Hiring!
    • Partners
    • Press
    • Contact
  • Products
    • Kong Gateway
    • Kong Enterprise
    • Get Started
    • Subscriptions
  • Resources
    • eBooks
    • Webinars
    • Briefs
    • Blog
    • API Gateway
    • Microservices
  • Open Source
    • Install Kong Gateway
    • Kong Community
    • Kubernetes Ingress
    • Kuma
    • Insomnia
  • Solutions
    • Decentralize
    • Secure & Govern
    • Create a Dev Platform
    • API Gateway
    • Kubernetes
    • Service Mesh
Star
  • Terms•Privacy
© Kong Inc. 2021