Run a function on one path, and roll it back
Run a function instance on one path and one method with a Run Function rule, and roll the path back by turning the rule off.
You run a function on one path and one method of an application with a Run Function rule, and roll the path back by turning that rule off, from Azion Console, the API, or the Azion CLI. To create the function and its instance first, refer to Functions quickstart.
A rule for one path moves that path to the function, while every other path keeps the rule that served it before. The rule’s Active switch, the active field in the API, is the rollback: a rule turned off does not run, and the path goes back to the earlier rule with no change to any other rule.
- Every request matches the first rule, which sends it to the origin through a connector.
- A
GETrequest for/api/itemsalso matches the second rule while it is active, and the function instance answers it. - Any other request, and every request once the second rule is off, is answered by the origin.
Prerequisites
Console
- An application served by a workload, with a rule that sends every request to a connector. To create them, refer to Applications quickstart.
- Application Accelerator on the application, which the Run Function behavior requires. To turn it on, refer to Turn on Application Accelerator.
- A function instance on the application. To create the function and the instance, refer to Functions quickstart, which creates both.
The examples run the instance <function-instance-id> on GET /api/items of the application <application-id>, on the domain www.example.com. Replace them with your values.
Create the rule for the path and the method
The rule carries two criteria groups, one for the path and one for the method. Groups join with and, so a request matches only when both match, and a POST to the same path keeps reaching the origin. Neither ${uri} nor ${request_method} needs a Product on the application.
A new rule is created at the end of the Request Phase, after the rule that sends every path to the connector. A rule placed after one that ends the processing, such as Deliver or Finish Request Phase, never runs for the requests that rule matches.
Console
To create the rule in Azion Console:
Access Azion Console > Applications > your application, then go to the Rules Engine tab.
Enter a name that identifies the path. For example: function - GET /api/items.
In the Criteria section, set the criterion to ${uri} is equal /api/items.
Add a second criteria group with one criterion: ${request_method} is equal GET.
The rule appears in the Request list, after the rule that sends every path to the connector.
GET /api/items runs the function instance, and every other request keeps reaching the origin. A new rule takes a few minutes to reach every data center. When Run Function is missing from the behaviors list, the application needs Application Accelerator.
In the Modernize a monolithic application without a rewrite use case, this section takes these values:
| Setting | Value |
|---|---|
| Rule name | strangler - GET /api/stores |
| Criteria | one group with ${uri} is equal /api/stores, and a second group with ${request_method} is equal GET |
| Behavior | Run Function with the stores-route instance, whose ID goes in attributes.value in the API |
GET /api/stores is answered by the function, and every other request still reaches the monolith. A rule change takes a few minutes to reach every data center, so the cut-over and the rollback each spread over that time, and both versions of the route answer while they do.
In the Build AI agents use case, this section takes these values:
| Setting | Value |
|---|---|
| Rule | agent - tasks and approvals, in the Request Phase |
| Criteria | One group, ${uri} starts with /api/agent/, in place of this guide’s path and method groups |
| Behavior | Run Function, selecting the ops-agent instance |
A task sent to /api/agent/tasks runs until the model answers, a refund needs approval, or six steps pass, and every start, pause, decision, and end lands in task_events. A new rule takes a few minutes to propagate.
Roll the path back
Turning the rule off keeps its criteria and its behavior, so turning it on again moves the path back to the function. The update changes active alone.
Console
To turn the rule off in Azion Console:
Access Azion Console > Applications > your application, then go to the Rules Engine tab.
In the Request list, select function - GET /api/items.
In the Status section, turn off Active.
GET /api/items reaches the origin again once the change propagates. While it propagates, some data centers still run the function, so both versions answer for a few minutes.
Check which version answers
The Upstream Addr of a request record names who answered it, and 127.0.0.1:1666 marks Azion Runtime. To check the path in Real-Time Events:
Access Azion Console > Real-Time Events.
In Filter by, enter request_uri like '/api/items%'.
While the rule is active, the GET records carry 127.0.0.1:1666. After the rollback, new records carry the address and the port of the origin. For the filter syntax, refer to Filter events.
In the Modernize a monolithic application without a rewrite use case, expect:
- Every other route still reaches the monolith. In Real-Time Events, the HTTP Requests records that match
request_uri like '/api/stores%'carry Upstream Addr127.0.0.1:1666onGET, which marks Azion Runtime. The records of any other path of the site carry the monolith’s address,<monolith-ip>, with its port. - Writes still reach the monolith. The record of a
POSTto/api/storescarries the monolith’s address, because the cut-over rule matches onlyGET. - The rollback holds. A few minutes after the rule is turned off,
/api/storesanswers from the monolith, and new records for the path carry<monolith-ip>.