How to instantiate edge functions in your application
Instantiate serverless functions directly within your edge application.
This guide uses the pre-configured Azion - Hello World function, which is linked to your account. You can repeat this process using any function already available on Azion Marketplace or develop your own function.
- Access Azion Console > Edge Application.
- Click the edge application you want to configure.
- Activate the Edge Functions module to enable functions.
- Click the Save button.
- 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.
The functions page now lists the newly created instance. However, this new function isn’t yet active in your application. You need to define what will trigger the function in your application. To invoke the instantiated function in the URI xxxxxxxxxx.map.azionedge.net/hello-world
:
- Still on the Edge Application page, navigate to the Rules Engine tab.
- Click the + Rule button.
- Give a name for your rule.
- Select Request Phase.
- Under the Criteria section, select the variable
${uri}
.
- As a comparison operator, select is equal.
- As an argument, add
/hello-world
. - In the Behaviors section, select Run Function from the behavior list.
- Select the Hello World function.
- Click the Save button.
To see your function running, access your application using its domain and the URI set in the rule, which is in the format xxxxxxxxx.map.azionedge.net/hello-world
.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and select Edge Application.
- Click the edge application you want to configure.
- Activate the Edge Functions module to enable functions.
- Click the Save button.
- 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.
The functions page now lists the newly created instance. However, this new function isn’t yet active in your application. You need to define what will trigger the function in your application. To invoke the instantiated function in the URI xxxxxxxxxx.map.azionedge.net/hello-world
:
- Still on the Edge Application page, navigate to the Rules Engine tab.
- Click the Add Rule button and select Request Phase.
- Give a name for your rule.
- Under the Criteria section, select the variable
${uri}
.
- As a comparison operator, select is equal.
- As an argument, add
/hello-world
. - In the Behaviors section, select Run Function from the behavior list.
- Select the Hello World function.
- Click the Save button.
To see your function running, access your application using its domain and the URI set in the rule, which is in the format xxxxxxxxx.map.azionedge.net/hello-world
.
- Run the following
PATCH
request in your terminal, replacing[TOKEN VALUE]
with your personal token and the<edge_application_id>
variable with your edge application ID to activate the Edge Functions module:
- You’ll receive a response with the updated value.
- Run the following
GET
request to retrieve theedge_function_id
of the Hello World function:
- You’ll receive a response similar to this:
- Copy the
<edge_function_id>
value. - Run the following
POST
request, replacing the edge function ID value with the value you received in the previous response:
- You’ll receive a response similar to this:
Key | Description |
---|---|
edge_function_id | The ID of the edge function. This is not the same as the ID of the instantiated function, which is unique for each application’s function instance. |
name | Name of the instantiated function. |
args | Definition of arguments required for the function. Some functions don’t take arguments. |
id | ID of the instantiated function. |
- Run the following
POST
request in your terminal, replacing[TOKEN VALUE]
with your personal token, the<edge_application_id>
variable with your edge application ID, and the<edge_function_instance_id>
variable with the function instance ID received in the previous response:
- You’ll receive a response similar to this, confirming your function was created successfully:
- Wait a few minutes for the changes to propagate.
To see your function running, access your application using its domain and the URI set in the rule, which is in the format xxxxxxxxx.map.azionedge.net/hello-world
.