Skip to main content

azure-functions

Invokes an Azure Function as the upstream.

Category ServerlessAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin azure-functionsPriority -1900

What it does​

azure-functions answers the requests on a route from an Azure Function instead of an upstream. The gateway calls the function at Function URI with the function key under API key. A route that names no key of its own uses the Master API key of the plugin metadata.

The client gets what the function answers, its status and its body, 200 and order 42 from the function in the example. The route in the example carries no upstream of its own.

When to use it​

  • An orders endpoint written as an Azure Function, published on the same host as the routes your own backend instances serve.
  • A function that expects its function key, which the gateway adds so that no client ever holds it.
  • Several routes whose functions accept the same key, kept once for the environment as the master key.
  • One path of an API moved to a function, a report export for example, while the rest stays on the backend.

Not for a backend of your own — see Upstream (Upstreams are the backends that routes and services send traffic to), a function hosted on AWS Lambda — see aws-lambda (Invokes an AWS Lambda function as the upstream) or code that runs inside the gateway itself — see serverless-pre-function (Runs Lua functions before the other plugins of a phase).

Set it up​

Serve the route from an Azure Function called with its own key​

Under Basics set Function URI to https://orders.azurewebsites.net/api/orders and fill Authorization as in the JSON below. Under Behavior set Timeout to 10000 milliseconds.

azure-functions · as the console saves it
{
"function_uri": "https://orders.azurewebsites.net/api/orders",
"authorization": {
"apikey": "<secret>"
},
"timeout": 10000
}

More scenarios​

Use one master key for every route that names no key of its ownenvironment-wide settings

Set Master API key to <secret> and set Master client ID to api-gateway.

azure-functions environment-wide settings · as the console saves it
{
"master_apikey": "<secret>",
"master_clientid": "api-gateway"
}

Things to know​

  • API key — The key reaches the function in the x-functions-key header. In the example the function answers only a request that carries it, and the client receives its 200.
  • Authorization — The keys in this plugin's environment-wide metadata are used only when this object has no Authorization and the request brings no x-functions-key or x-functions-clientid. An Authorization block that is present but empty sends no key at all.
  • On a route whose azure-functions has no Authorization, the function receives the master key of the plugin metadata and its Master client ID. In the example the function answers called by client api-gateway.
  • Function URI — An empty Function URI is refused when you save.
  • AdviceGive each route the function key of its own function, and keep the master key for the routes you mean to share it.

Settings​

The fields as the console shows them, section by section.

Basics​

Function URIfunction_uristringRequired

The function's full URL, to which whatever a route wildcard matched is appended.

at least 1 character · example https://orders.azurewebsites.net/api/orders
Authorizationauthorizationobject
API keyauthorization.apikeystring

Stored on the engine and shown only to roles that manage this object.

Client IDauthorization.clientidstring

The id of the function key above, sent as x-functions-clientid beside it when the request carries neither x-functions-key nor x-functions-clientid of its own.

Behavior​

Timeouttimeoutintegerdefault 3000
at least 100 · in milliseconds
SSL verifyssl_verifybooleandefault true

Advanced​

Request body limitmax_req_body_sizeintegerdefault 67108864

The largest request body in bytes that is forwarded, where a larger one is rejected with 400.

at least 1
Keepalivekeepalivebooleandefault true
Keepalive poolkeepalive_poolintegerdefault 5
at least 1
Keepalive timeoutkeepalive_timeoutintegerdefault 60000
at least 1000 · in milliseconds

Environment-wide settings​

Set once per environment, under Plugins › azure-functions. Every azure-functions in the environment uses these.

Master API keymaster_apikeystringdefault

Read for a route whose own authorization is missing entirely, and never when the request already carries x-functions-key or x-functions-clientid. Stored on the engine and shown only to roles that manage this object.

Master client IDmaster_clientidstringdefault

Every plugin also has Enabled, Priority, Filter, Error response and Pre-function: see Plugin execution settings.

G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.
Facts
Category
Serverless
Add it to
Route, Service, Consumer, Consumer group, Global rule, Plugin config
Engine plugin
azure-functions
Priority
-1900