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
- 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.
- A personal token, for the API procedures.
- The Azion CLI installed and authorized, for the CLI procedures.
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.
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.
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.
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.