Summary

ModProxy is an Hakuna Cloud trigger that react to incoming HTTPS requests (ModProxy support both HTTPS and HTTP). ModProxy stop a cloud server when there are no incoming requests, and starts it as soon as a new request is received.

This trigger is supported by all Cloud Providers

Use Cases

  • Host a private NPM registry using an EC2 instance. With ModProxy, the instance is stopped when nobody is accessing the npm repo, but as soon as a package is requested (npm install @scoped/package) , ModProxy start the EC2 instance, and npm will install the package. Save, on average, 60% of costs.

  • Deploy a web application in a test environment (as example, using AWS Fargate) for each development branch to run test and Q/A. The environment is automatically destroyed when no one is accessing it, but it can be restored immediately when QA requires to test it.

How does it work

ModProxy looks for a VHost whose vhost.hostname match exactly the Host header in the incoming HTTP request. Then, if the status of the cloud server (instance) is

  • running -> ModProxy proxy the request to the cloud server;
  • stopped -> ModProxy pause the incoming request, starts the server, check that the service is running and then proxy the incoming request;

ModProxy send periodically to the instance a ping request, a simple http request to http://<instance_ip>:80/. The response is matched against a set of regular expressions defined in vhost.ping. The instance is considered running when the first regexp match the received http response.

ModProxy stop the instance after 30 minutes after the last http request received.

Configuration

A ModProxy trigger is automatically associated to a VHost when it is created. The only required step to use ModProxy is to configure your DNS to point the hostname to one of our public load balancers:

Europe: eu1.lb.hakuna.cloud
North America: na1.lb.hakuna.cloud

Example:

example.com CNAME eu1.lb.hakuna.cloud

Ping

ModProxy check if the cloud server is up and running by sending an http request to it’s ip address. It is possible to customize the request by configuring the ping attribute of the VHost object:

"ping": {
    "method": "GET",
    "regex": {
      "statusCode": "^[2-4]",
      "headers": "(?!)",
      "body": "(?!)"
    }
  }

A cloud server is considered up and running if the http request succeed, and if the http response pass at least one of the conditions expresed in the regex object.

  • method: HTTP method to use
    • default: HEAD
  • regex.statusCode: A regular expression that is tested against the HTTP status code of the response; this is tested as first
    • default: ^[2-4] (math any status code between 200 and 499)
  • regex.headers: A regular expression that is tested against the headers of the response; this is tested as second
    • default: (?!) (never match)
  • regex.body: A regular expression that is tested agains the body of the received http response; this test is executed as last
    • default: (?!) (never match)

Stop Timeout

ModProxy stop the instance after 30 minutes after the last http request received. It is possible to specify a custom interval modifying the VHost property stopOptions.timeoutShutdown, expressing an interval in milliseconds.

hakuna vhost update -n <Vhost hostname> -c stopOptions.timeoutShutdown=<Custom Timeout in Milliseconds>

Alias records

An alias record is an additional FQDN that can be associated to a VHost. It can be used if the cloud server host multiple services. A typical example is a server with an Apache HTTP/NGINX server configured as reverse proxy with virtual hosting.

A VHost act as a normal hostname, unless it is not identified as whitelisted. Requests received on a whitelisted alias do not trigger the start and doesn’t count for the stop of a VHost

Setup

Alias are managed using the the CLI. To create an alias, run the command

hakuna alias create

then choose the VHost to associate to the new alias. By default, alias are created as not-whitelisted

To list all the existing alias, run the command

hakuna alias list

To whitelist an alias, run this command:

hakuna alias update -n <Alias hostname> -c options.whitelisted=true

Whitelisted alias

If an alias is marked as whitelisted, then requests to the alias are ignored by the ModProxy logic:

Whitelisted Request is proxied Instance is started Instance shutdown is scheduled
true
false (or not set)