Serve a status page from a function
Serve a status or error page from the Hello World function on an application, with a function instance and a Rules Engine rule, and no request to the origin.
You can serve a status or error page from the Hello World function on an application, from Azion Console. The function answers on Azion’s distributed infrastructure, so the request never reaches your origin. To install Hello World from Azion Marketplace with a status code and a body instead, refer to Install the Hello World integration.
A status page reports the state of a service, so you can monitor it and inform its users. The example on this page answers requests to www.myapplication.com/api_service with a notice that the service is temporarily unavailable. With Data Stream, you can also send the access records of the page to a SIEM (Security Information and Event Management), Big Data, or log servers, and analyze the data there.
Prerequisites
- Access to Azion Console. To sign in, refer to How to access Azion Console.
- An application that receives the requests for the status page.
- Application Accelerator and Functions turned on for the application. The Run Function behavior requires both. For more information, refer to Rules Engine for Applications.
Create the function instance
An application runs a function through an instance, and the instance passes its Args to the function. Azion provides the Hello World function, and its Args set the HTTP status code and the message of the response. The example instance uses these Args:
To create the instance in Azion Console:
Access Azion Console > Applications, then select the application that serves the status page.
Enter a distinctive name. For example: MyHelloWorld.
In the Function field, select Hello World. The Code field shows the code of the function for reference only.
In the Args tab, enter the JSON with your status code and message.
The MyHelloWorld instance is on the application. It runs only after a Rules Engine rule selects it.
Add the rule that runs the instance
A Rules Engine rule sets the criteria a request must meet and the behaviors that run when it does. You can add the behavior to the Default Rule or create a new rule. Here, a new rule runs MyHelloWorld when the URI starts with /api_service.
To create the rule in Azion Console:
Access Azion Console > Applications, then select the application that serves the status page.
Enter a name for the rule.
In the Criteria section, select ${uri} as the variable and starts_with as the operator, and enter /api_service as the argument.
In the Behaviors section, select Run Function, then select MyHelloWorld.
A request to www.myapplication.com/api_service returns the status code 503 with the body We are working hard to serve you better!.