Managing your edge functions with Azion CLI
Manage your edge functions using the Azion CLI. It’s common for an edge application to use several functions present in an Edge Library.
1. Prerequisites
Section titled 1. Prerequisites- Install Azion CLI.
- Create a personal token or use an existing one that identifies you on the Azion’s platform.
2. Listing you functions
Section titled 2. Listing you functionsInitially, you can list the edge functions available in your library, including the pre-configured Azion - Hello World
function.
To list your edge functions, run the command:
azioncli edge_functions list
A list of your functions will be presented on the monitor, as in this example:
ID NAME LANGUAGE ACTIVE 3976 Azion - Hello World javascript true 6598 func01 javascript true
The azioncli edge_functions list
command responded with a table consisting of four columns:
- ID: unique identifier of the edge function on the Azion’s platform.
- NAME: name of the function.
- LANGUAGE: programming language or framework of the function.
- ACTIVE: status of the function, which can be active (true) or inactive (false).
3. Creating an edge function
Section titled 3. Creating an edge functionCreate a new edge function directly from the CLI, without having to resort to RTM. Initially, we’ll need a JavaScript file containing the function code. If you don’t have a file in the current directory, create one with the command below:
echo "alert('My new JavaScript function');" > my-func.js
After running the command, verify the creation of the my-func.js
file with the ls
command.
Now that you have a file with the JavaScript function, you can create your edge function with it. To do so, type the following command:
azioncli edge_functions create --name my-new-ef --code ./my-func.js --active true
CLI response:
Created Edge Function with ID 6823
The CLI responds with the ID of the newly created function. To confirm it, use the list command again:
azioncli edge_functions list
CLI response:
ID NAME LANGUAGE ACTIVE 3976 Azion - Hello World javascript true 6598 func01 javascript true 6823 my-new-ef javascript true
Relative to the list in the previous example, this time the list command included the my-new-ef
function with ID 6823, created by the create command.
4. Deleting an edge function
Section titled 4. Deleting an edge functionTo delete the newly created my-new-ef
function, run the delete command with the ID parameter of the function:
azioncli edge_functions delete --function-id 6823
CLI response:
Edge Function 6823 was successfully deleted
Run the list command again. The CLI will present the following table:
ID NAME LANGUAGE ACTIVE 3976 Azion - Hello World javascript true 6598 func01 javascript true
Note that the my-new-ef
function, whose ID was 6823, no longer appears in the list. As a suggestion, you can access RTM to analyze the results of the CLI commands presented in this example.
Contributors