azure-functions
Invokes an Azure Function as the upstream.
azure-functionsPriority -1900What 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.
{
"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.
{
"master_apikey": "<secret>",
"master_clientid": "api-gateway"
}
Things to know
- API key — The key reaches the function in the
x-functions-keyheader. In the example the function answers only a request that carries it, and the client receives its200. - 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_uristringRequiredThe function's full URL, to which whatever a route wildcard matched is appended.
https://orders.azurewebsites.net/api/ordersauthorizationobjectauthorization.apikeystringStored on the engine and shown only to roles that manage this object.
authorization.clientidstringThe 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
timeoutintegerdefault 3000ssl_verifybooleandefault trueAdvanced
max_req_body_sizeintegerdefault 67108864The largest request body in bytes that is forwarded, where a larger one is rejected with 400.
keepalivebooleandefault truekeepalive_poolintegerdefault 5keepalive_timeoutintegerdefault 60000Environment-wide settings
Set once per environment, under Plugins › azure-functions. Every azure-functions in the environment uses these.
master_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_clientidstringdefault