Voice Activated Load Balancing? Could it actually work

Voice Activated Load Balancing? Could it actually work

Performance Published on 3 mins Last updated

We'd heard the marketing team had come up with an idea for an April fools joke of releasing a product called Enterprise VAL, the voice activated load balancer. We liked the idea but thought wouldn't it be cool if it actually worked? So we built it.

How it works

As we are not releasing this and just needed a proof of concept the quickest and easiest method would be best. So we decided on using Amazon Alexa for the voice control. We use AWS a lot here and know the documentation is good and it is easy to work with.

After a bit of reading and borrowing our colleagues Echo (Thanks Andy!) we had some idea of what to do and starting setting up our new Alexa skill.

Setting up the Skill

We decided that we would like to be able to change server states and bring them online, offline or drain them. So asking Alexa to do this would look like “Alexa ask Val to change status of website1 to drain”. So we started work with this as our goal.

The voice commands in Alexa are controlled by setting up Skills. These skills consist of 4 main parts.

  • Invocation Name - What word to use to active your skill.
  • Intent Schema - This represents an action that fulfils a voice command.
  • Slots - These at your parameters used in the command passed to your endpoint.
  • Sample Utterances - These are the commands that people say to interact with the skill.

So it was just a case of configuring these.

Invocation Name was set to “VAL”

Intent Schema

{
   "intents": [
      {
         "slots": [
            {
               "name": "server",
               "type": "OBJECT"
            },
            {
               "name": "action",
               "type": "ACTION"
            }
         ],
         "intent": "change"
      }
   ]
}

Custom Slot types
ACTION online | halt | offline | drain
OBJECT server | website

Sample Utterances

change status of {server} to {action}
change status {server} to {action}
change status of {server} to be {action}
change {server} to {action}

We used a HTTPS endpoint instead of Lambda so we could interact with it directly with the load balancer and run the commands needed.

For your skill to be published you need a certificate from a trusted authority. We started off using a certificate from LetsEncrypt but ran into to issues so went back to a self-signed certificate for testing.

Configuring the load balancer

Now we did cheat a little here as we only wanted a proof of concept so ignored all validation and hard coded the virtual server name to “loadbalancer.org”. After all we do have more important things to spend our time on like version 9.

We ended up with this as our endpoint code. Actioning the Alexa requests is quite simple you check what the intent is, pull out your slot values, then action and reply. The request and reply are in JSON and easy to work with.

In response to our request “Alexa ask Val to change status of website1 to drain”
We set Alexa to reply with “Server 'website1' successfully actioned drain”

require_once("online_offline.inc");

$EchoJArray = json_decode(file_get_contents('php://input'));
$RequestType = $EchoJArray->request->type;
$server = $EchoJArray->request->intent->slots->server->value;
$action = $EchoJArray->request->intent->slots->action->value;

$intent = $EchoJArray->request->intent->name;
$_SERVER["PHP_AUTH_USER"] = "loadbalancer";
if ($intent == "change") {
   switch ($EchoJArray->request->intent->slots->action->value){
      case "online":
      case "enable":
         action($server,"online");
         break;
      case "offline":
      case "disable":
      case "halt":
         action($server,"halt");
         break;
      case "drain":
         action($server,"drain");
         break;
   }
} 
function action($server,$action){
   l4_l7_selector($server,"loadbalancer.org",$action);
   $JsonOut = '{
      "version": "1.0",
      "sessionAttributes": {
         "countActionList": {
            "read": true,
            "category": true,
            "currentTask": "none",
            "currentStep": 0
         }
      },
      "response": {
         "outputSpeech": {
            "type": "PlainText",
            "text": "Server '. $server . ' successfully actioned ' . $action . '"
         }
      }
   }';
   $size = strlen($JsonOut);
   header('Content-Type: application/json');
   header("Content-length: $size");
   echo $JsonOut;
}
0:00
/

That is it Alexa, can now change the state of our load balanced servers. I was surprised at how easy it was to work with Alexa. There were a couple of gotchas though. You need to set your skill language to the same as what your Echo is set to, no mixing English US and English UK here. Also, using Let's Encrypt certificates looks like it needs a bit of work to make work but overall Amazon has made it very easy to work with. While it's some way off full voice control, the ability is there if you put the work in.