Azion CLI function
Azion CLI commands that create, list, describe, update, and delete the functions of your account, with each flag, its type, and its default.
The Azion CLI function commands create, list, describe, update, and delete Functions in the functions library of your account. Each function holds its code, its default arguments, and the environment it runs in, an application or a firewall. An application runs a function through a function instance, which the function-instance commands manage. The options every command accepts, such as --format, --out, and -y, are on Global options.
Create
azion create function adds a function to the functions library from a code file and the settings you pass:
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--active | — | string | — | Required unless --file is set. Turns the function on (true) or off (false). Without it, the command asks you to select true or false. |
--args | — | string | — | Path to a JSON file with the arguments of the function. The command stores the content of the file as default_args. |
--code | — | string | — | Required unless --file is set. Path to the file with the code of the function. Without it, the command asks for the path. |
--execution-environment | — | string | — | Where the function runs: application or firewall. |
--file | — | string | — | Path to a JSON file with the attributes of the function. Use - to read the JSON from standard input. |
--name | — | string | — | Name of the function. |
--execution-environment takes only application or firewall. Any other value, such as edge_application, is refused with this error:
This file, ./code/function.js, holds the code of the function. It answers every request with the text my-function:
This command creates an active function named my-function from that file, with the arguments in ./code/args.json, to run in an application:
The command prints the ID of the function:
List
azion list function lists the functions of your account, 50 to a page:
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--details | — | — | — | Adds the LAST EDITOR, REFERENCE COUNT, and EXECUTION ENVIRONMENT columns to the ID, NAME, and ACTIVE columns. |
--filter | — | string | — | Name to filter the list by. |
--order-by | — | string | — | Field to sort the list by. |
--page | — | int | 1 | Number of the page to return. |
--page-size | — | int | 50 | Number of functions on each page. |
This command returns the first page of a list split into pages of two functions:
The command prints one row per function:
Describe
azion describe function prints the settings of one function:
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--function-id | — | int | — | ID of the function to describe. |
--with-code | — | — | — | Prints the same fields as the command without it. The code of the function is in the code field of the --format json output. |
This command describes the function with ID 12359:
The command prints the ID, the name, the last editor, the state, and the reference count of the function:
With --format json, the command prints the full object: active, azion_form, code, default_args, execution_environment, id, is_versioned, last_editor, last_modified, name, product_version, reference_count, resource_version, runtime, vendor, version, version_id, and version_state. The code field holds the source of the function, and default_args holds the content of the --args file.
With an ID that does not exist, the command fails with this error:
Update
azion update function changes the name, the state, the code, the arguments, or the environment of a function:
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--active | — | string | — | Turns the function on (true) or off (false). |
--args | — | string | — | Path to a JSON file with the new arguments of the function. Its content replaces default_args. |
--code | — | string | — | Path to the file with the new code of the function. |
--execution-environment | — | string | — | Where the function runs: application or firewall. |
--file | — | string | — | Path to a JSON file with the attributes to change. Use - to read the JSON from standard input. |
--function-id | — | int | — | Required, with --file too. ID of the function to update. Without it, the command asks for the ID, even when the --file JSON carries "id". |
--name | — | string | — | New name of the function. |
This command renames the function with ID 12359 to my-function-renamed and turns it off:
The command prints the ID of the updated function:
With --code and --args, the same command replaces the code and the stored arguments of the function. The default_args field then holds the content of the new --args file.
Delete
azion delete function deletes a function from the functions library:
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--function-id | — | int | — | ID of the function to delete. |
This command deletes the function with ID 12370:
The command confirms the deletion:
Use a JSON file
azion create function and azion update function read the attributes of the function from a JSON file with --file.
This file creates an active function named my-firewall-function that runs in a firewall. It carries the code inline, in the code field:
Pass the file to the create command:
The command prints the ID of the function:
On update, the command does not read "id" from the file, so pass --function-id on the command line. This file renames the function with ID 12370:
Pass the file and the ID to the update command:
The command prints the ID of the updated function:
The function keeps the fields the file leaves out. In this example, it stays active.