End-user monitoring of your website with CloudWatch Synthetics
There are countless reasons why your website is not working as your users expect. From a technical point of view, you can monitor your load balancers, your web servers, and your database. But what if that external script that you embed is breaking your site? Expired TLS certificate? Something wrong with DNS? How can you test that your website works for real users?
Do you prefer listening to a podcast episode over reading a blog post? Here you go!
Browsers can be used in an automated way controlled by a script. Wait for an element to become visible. Click on a link. Enter a form field. puppeteer allows you to remote control a headless Chrome browser in Node.js and is maintained by Google. We can monitor the user experience on our website if we can find a way to run a puppeteer script at regular intervals and record the results.
And that’s where Amazon CloudWatch Synthetics enters the stage. It allows you to create canaries to execute puppeteer scripts on a schedule. Each run creates detailed logs, screenshots, and a record of all network calls in HAR format uploaded to S3. All you need to do is provide a script that performs the test, or use one of the blueprints. The following Node.js script opens
https://marbot.io, waits for an
<h1> HTML element, checks the title and status code, and performs a screenshot.
const synthetics = require('Synthetics'); // CloudWatch Synthetics lib
The rest is taken care of by CloudWatch Synthetics and is presented like this:
Looking for a new challenge?
Want to get notified about failed canary runs? Create a CloudWatch Alarm that watches the metrics of the canary to alert you if things go wrong. I created a CloudFormation template to help you with the setup (don’t forget to resolve the
TODOs in the template!).
Don’t forget to check out the CloudWatch pricing details.
I also integrated CloudWatch Synthetics into marbot. You can set up your external website from Slack and receive alerts in Slack like this:
- Send a message to marbot on a channel and ask him to monitor your website.
- Select your preferred way of interacting with AWS (Management Console, CLI).
- Set the monitoring goal to Synthetics website.
- Select your AWS region.
- Follow marbot to deploy a CloudFormation stack to set up CloudWatch Synthetics, CloudWatch Alarms, and much more.
That’s it. Your website is now monitored from an end-user perspective. If things go wrong, you will receive a message in Slack.
Are you interested in marbot? Configure AWS monitoring, receive alerts, solve incidents from Slack.