Function Instances
Look up the fields of a Function Instance, its Args, and how the Run Function behavior invokes it.
A Function Instance is the entity that binds one Function to one Application. The Function Instance carries the Args, the arguments passed into the context of the Function’s execution in JSON format: args in the API, and the Arguments section in Azion Console. A Function Instance sets its name, its Args, its form schema, and whether it is active, and it leaves the code of the Function as it is.
A rule in Rules Engine invokes the Function Instance, not the Function. The same Function can be instantiated in more than one Application, and each Function Instance carries its own Args. A Function Instance runs only when a rule with Run Function invokes it.
A Firewall instantiates Functions the same way. A Function Instance on a Firewall runs its Function before the request reaches the Application, so the Function can stop the request there. A Function Instance on an Application runs its Function as part of serving the request. For the Function Instances of a Firewall, refer to Function instances for Firewall. For their bounds, refer to Firewall limits.
Function Instance fields
The Azion API creates a Function Instance under the Application it belongs to. These are the fields you set:
| Field | Type | Required | Description |
|---|---|---|---|
name |
string, 1 to 100 characters | Yes | Name of the Function Instance. |
function |
integer | Yes | ID of the Function the Function Instance binds, not of the Function Instance. |
args |
JSON object or array | No | Arguments passed into the context of the Function’s execution. |
azion_form |
JSON object | No | A JSON Schema that renders the args as a form. |
active |
boolean | No | Whether the Function Instance is active. |
When the Function Instance sets no args, the default_args of the Function are used. When it sets no azion_form, an empty object is used.
The API returns four more fields:
id, the ID of the Function Instance.last_editor, the email address of the account that last changed it.last_modified, the timestamp of that change.created_at, the timestamp of creation.
A POST request to the functions resource of an Application creates a Function Instance:
The API answers 202 with the created object:
The "state": "pending" value means the change takes a few minutes to propagate before it takes effect.
The API serves the Function Instances of an Application under /workspace/applications/<application-id>/functions. In the path of one Function Instance, <function-instance-id> is the ID of the Function Instance, not of the Function:
| Operation | Method and path |
|---|---|
| Create a Function Instance | POST /workspace/applications/<application-id>/functions |
| List the Function Instances of an Application | GET /workspace/applications/<application-id>/functions |
| Read one Function Instance | GET /workspace/applications/<application-id>/functions/<function-instance-id> |
| Replace a Function Instance | PUT /workspace/applications/<application-id>/functions/<function-instance-id> |
| Change part of a Function Instance | PATCH /workspace/applications/<application-id>/functions/<function-instance-id> |
| Delete a Function Instance | DELETE /workspace/applications/<application-id>/functions/<function-instance-id> |
Instantiate a function on an application shows how to create a Function Instance in Azion Console. In the azion.config.js file that Azion CLI reads, a Function Instance carries name, args, and active, and ref names the Function by name or by ID.
Args
Args are the arguments a Function Instance passes into the context of the Function’s execution, written as a JSON object or array. The code reads a key at run time and the Function 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 a Function Instance override the keys they repeat, and every key the Function 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 Functions limits.
Args are the configuration of one Function Instance. 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 a Function Instance. The rule holds the ID of the Function Instance, and the phase and the criteria of the rule decide when it runs. 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 Functions turned on in the Application. In the Response Phase, it runs only Functions written in Lua. In the Azion API, the behavior is run_function, and its value attribute holds the ID of the Function Instance.
For the execution phases, the criteria, and the order behaviors run in, refer to How Functions works.
CLI
Azion CLI manages Function Instances with five commands under the function-instance noun. Every command takes --application-id, and a command that acts on one Function Instance takes its ID in --instance-id.
| Command | What it does | Flags |
|---|---|---|
azion create function-instance |
Creates a Function Instance | --application-id, --function-id, --name, --args, --active, --file |
azion list function-instance |
Lists the Function Instances of an Application | --application-id, --details, --filter, --order-by, --page, --page-size |
azion describe function-instance |
Returns one Function Instance | --application-id, --instance-id |
azion update function-instance |
Changes a Function Instance | --application-id, --instance-id, --function-id, --name, --args, --active, --file |
azion delete function-instance |
Deletes a Function Instance | --application-id, --instance-id |
--function-id sets the function field, and --args sets args. On azion create function-instance and azion update function-instance, --active defaults to true.