How to run serverless functions on Azion
Edge Functions is a module of the Azion Edge Platform that allows you to program and execute serverless functions.
Go to Edge Functions for Edge Application referenceTo run a function, you must:
- Create your own function or use any of those already available on Azion Marketplace.
- Instantiate a function in an edge application.
- Define activation triggers within Rules Engine.
Creating a new edge function
To create an edge function:
- Access Azion Console > Edge Functions.
- Click on + Edge Function.
- Choose a name for your function.
- Write your code.
- Click the Save button.
- Access Real-Time Manager (RTM).
- On the upper-left corner, click the three horizontal lines to open the Products menu.
- Under EDGE LIBRARIES, select Edge Functions.
- Click on Add Function.
- Choose a name for your function.
- Write your code.
- Click the Save button.
Instantiating an edge function
To demonstrate how to instantiate and run a function on an edge application, this guide will use the pre-configured Azion - Hello World function. To instantiate an edge function on an edge application:
- Access Azion Console > Edge Application.
- Click on the edge application to which you want to add a function.
- Go to the Functions Instances tab.
- Click + Function Instance.
- Name your function instance. For example:
Hello World function
. - Select the Azion - Hello World function.
- Click the Save button.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, click the three horizontal lines to open the Products menu.
- Under the section BUILD, select Edge Application.
- Click the edge application you want to add a function.
- Go to the Functions tab.
- Click Add Function.
- Name your function instance. For example:
Hello World function
. - Select the Azion - Hello World function.
- Click the Save button.
Configuring function activation criteria
- In the same edge application, go to the Rules Engine tab.
- Click + Rule.
- Give your rule a name.
- Select Request Phase.
- In the Criteria section, select:
- If
${uri}
is equal/hello-world
.
- If
- In the Behaviors section, choose Run Function.
- Select the Hello World function
- Click Save.
Wait a few minutes for the propagation to be completed.
To see your instanced function, access your application using its domain and the URI set in the rule, which is in the format xxxxxxxxx.map.azionedge.net/hello-world
.
Now you’ve successfully configured and instantiated an edge function in an edge application.
- In the same edge application, go to the Rules Engine tab.
- Click New Rule and select Request Phase.
- Give your rule a name.
- In the Criteria section, select:
- If
${uri}
is equal/hello-world
.
- If
- In the Behaviors section, choose Run Function.
- Select the Hello World function
- Click Save.
Wait a few minutes for the propagation to be completed.
To see your instanced function, access your application using its domain and the URI set in the rule, which is in the format xxxxxxxxx.map.azionedge.net/hello-world
.
Now you’ve successfully configured and instantiated an edge function in an edge application.