How to monitor errors in a live Alexa skill with AWS services

Nicolò Gasparini
4 min readJun 1, 2019

Why should you monitor your skill after having it published on the Alexa Store?

After developing an Alexa Skill, you need to know and analyze what happens to your users.
The Amazon Alexa Developer Console provides some analytics tool that lets you monitor how many users you have, how they’re approaching and using your skill, which utterances they pronounce, but how do we manage errors?

Alexa Developer Console Analytics

If you have already published a skill using a lambda function, you will know that it won’t be approved in case of errors, but they can happen anyway if you mismanaged a parameter or forgot a special case.
The good thing to do in these cases is to insert in your code an Exception Handler, that will intercept all of these errors and return a custom message to your the user, such as “Oops, something went wrong, please try again later”.

This is the recommended approach, however, for most services, including Lambda functions, it means your code won’t actually fail, but rather succeed and just log an error. This is the reason why conventional fail tracking systems may fail in these cases.

Why can’t I send an alarm to an external service from my code?

The answer is simple, you can but maybe you shouldn’t.
Integrating an error tracking library may be the first choice for companies and developers who already owns some systems and have such a system, but doing so it may slow down your function in an environment where, with voice interaction and impatient users, time is everything.

In addition to that, the most common way to develop an Alexa skill’s core is to use AWS Lambda functions. Thanks to this serverless technology, we don’t have to think about deployment and availability of our service, but they do have some cons. Regardless your choice of the programming language, it may be difficult to include different services or libraries in your code.

These are the reasons why I’m going to share with you a simple way to create an alarm that, through email or other channels, can let you know when an error occurs in your lambda function and the user is left withouth a response.

How to set up the alarm

We will be using the main alarm management system provided by AWS: Cloudwatch.

To do so, we will base our alarm on Cloudwatch logs, that are automatically connected to every lambda function you have, you can find them by following this link in the Lambda page from the AWS console, or simply navigate to the Cloudwatch service page, under Logs.

Monitoring > View logs in CloudWatch

Here you will find evey Log Group for every service you are using

  • Select the Log Group for your lambda skill and click on Create Metric Filter
  • Enter a pattern for a log that will signify an error occured in your code, for
    example “?Error ?ERROR”.
    You can find here a set of rules on how to create a pattern
  • Test the pattern with different Log Data to see if it works as expected
  • Enter a Filter Name, that will identify it in case of multiple filters, and a Metric Name and Namespace. (I suggest opening the advanced options, setting 1 in case of event occuring, 0 in case of event not occurring)
  • Now click on Create Alarm
  • Set the Alarm to trigger when the event is >0 and treat missing data as good (not breaching treshold)
  • Select an action to occur when the alarm is triggered, such as a simple email

This is it! You will now receive an email everytime an error is logged in your lambda function connected to your Alexa skill.

--

--

Nicolò Gasparini

Software Engineer and full stack developer 💻 based in Italy — /in/nicologasparini/