Years ago, managing your infrastructure through voice was a science-fiction movie, but thanks to virtual assistants like Alexa it becomes a reality. In this post, I will show you how I was able to monitor my infrastructure on AWS using a simple Alexa Skill.
At a high level, the architecture of the skill is as follows:
I installed data collector agent (Telegraf) in each EC2 instance to collect metrics about system usage (disk, memory, cpu ..) and send them to a time-series database (InfluxDB)
Once my database is populated with metrics, Amazon echo will transform my voice commands to intents that will trigger a Lambda function, which will use the InfluxDB REST API to query the database.
Enough with talking, lets build this skill from scratch, clone the following GitHub repository:
1 | git clone https://github.com/mlabouardy/alexa-monitor |
Create a simple fleet of EC2 instances using Terraform. Install the AWS provider:
1 | terraform init |
Set your own AWS credentials in variables.tfvars. Create an execution plan:
1 | terraform plan --var-file=variables.tfvars |
Provision the infrastructure:
1 | terraform apply --var-file=variables.tfvars |
You should see the IP address for each machine:
Login to AWS Management Console, you should see your nodes has been created successfully:
To install Telegraf on each machine, I used Ansible, update the ansible/inventory with your nodes IP addresses as follows:
1 | [nodes] |
Execute the playbook:
1 | ansible-playbook -i inventory playbook.yml --private-key=key.pem |
If you connect via SSH to one of the server, you should see the Telegraf agent is running as Docker container:
In few seconds the InfluxDB database will be populated with some metrics:
Sign in to the Amazon Developer Portal, create a new Alexa Skill:
Create an invocation name – aws – This is the word that will trigger the Skill.
In the Intent Schema box, paste the following JSON code:
1 | { |
Create a new slot types to store the type of metric and machine hostname:
1 | TYPE_OF_METRICS: |
Under Uterrances, enter all the phrases that you think you might say to interact with the skill
1 | GetSystemUsage {Metric} usage of machine in {City} |
Click on “Next” and you will move onto a page that allows us to use an ARN (Amazon Resource Name) to link to AWS Lambda.
Before that, let’s create our lambda function, go to AWS Management Console and create a new lambda function from scratch:
Note: Select US East (N.Virginia), which is a supported region for Alexa Skill Kit.
Make sure the trigger is set to Alexa Skills Kit, then select Next.
The code provided uses the InfluxDB client to fetch metrics from database.
1 | function MetricsDB(){ |
Specify the .zip file name as your deployment package at the time you create the Lambda function. Don’t forget to set the InfluxDB Hostname & Database name as an environment variables:
Then go to the Configuration step of your Alexa Skill in the Amazon Developer Console and enter the Lambda Function ARN:
Click on “Next“. Under the “Service Simulator” section, you’ll be able to enter a sample utterance to trigger your skill:
Memory Usage
Disk usage:
CPU usage:
Test your skill on your Amazon Echo, Echo Dot, or any Alexa device by saying, “Alexa, ask AWS for disk usage of machine in Paris“
Drop your comments, feedback, or suggestions below — or connect with me directly on Twitter @mlabouardy.