Function instances
Bind a function to an application, set the JSON Args it receives, and invoke it with the Run Function behavior in Rules Engine.
A function instance binds one function to one application. The instance carries the Args, the arguments passed into the context of the function’s execution in JSON format. The code of the function cannot be edited at instantiation: an instance sets the Args and nothing else.
A rule in Rules Engine invokes the instance, not the function. The same function can be instantiated in more than one application, and each instance carries its own Args. An instance that no rule names never runs.
A firewall instantiates functions the same way. An instance on a firewall runs its function before the request reaches the application, so the function can stop the request there. An instance on an application runs its function as part of serving the request. Refer to Function instances for Firewall for the firewall object, and to Firewall limits for its bounds.
Instance fields
The Azion API creates an instance under the application it belongs to. These are the fields you set:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the instance. |
function | integer | Yes | ID of the function the instance binds. This ID differs from the ID of the instance. |
args | JSON object or array | No | Arguments passed into the context of the function’s execution. When the instance sets no args, the default_args of the function are used. |
azion_form | JSON object | No | A JSON Schema that renders the args as a form. When none is set, an empty object is used. |
active | boolean | No | Whether the instance is active. |
The API returns four more fields: id, the ID of the instance; last_editor, the email address of the account that last changed it; last_modified, the timestamp of that change; and created_at, the timestamp of creation.
A POST request to the functions resource of an application creates an instance:
The API answers with the created object:
The "state": "pending" value means the change takes a few minutes to propagate before it takes effect.
You create the same object in the Functions Instances tab of an application in Azion Console. In the azion.config.js file that Azion CLI reads, an instance carries name, args, and active, and ref names the function by name or by ID.
Args
Args are the arguments an instance passes into the context of the function’s execution, written as a JSON object. The code reads a key at run time and the instance decides its value, so one function behaves differently in each place it is instantiated. A function can define default Args of its own: the Args of an instance override the keys they repeat, and every key the instance leaves out keeps its default value.
An Args object that sets one key:
The Args object holds a maximum of 100 KB, and an object above that ceiling makes the function fail at instantiation. For every Functions limit, refer to Limits.
Args are per-instance configuration. Sensitive values such as API keys, credentials, and access tokens belong in environment variables instead.
Run Function behavior
Run Function is the Rules Engine behavior that invokes an instance. The rule names the instance, the execution phase, and the criteria that trigger it. When a request meets those criteria, the function runs on Azion’s distributed infrastructure.
Run Function is available in the Request Phase and in the Response Phase, and it requires the Application Accelerator module. In the Azion API, the behavior is run_function and its value attribute holds the ID of the instance.
For the execution phases, the criteria, and the order behaviors run in, refer to How Functions works.