paint-brush
AWS CloudWatch Synthetic Service Introduction and Quick Tips To Startby@ttan
775 reads
775 reads

AWS CloudWatch Synthetic Service Introduction and Quick Tips To Start

by ttanApril 29th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Amazon released CloudWatch Synthetic service a few days ago. The tool is to help you setup monitoring tool that can load web page, take screenshot or send API calls with auth token etc. It is part of the whole CloudWatch toolset so you can get all the nice web UI for the metrics and logs. It is quite easy to setup, details can be found here:https://aws.amazon.com/blogs/aws/new-use-cloudwatch-synthetics-to-monitor-sites-api-endpoints-web-workflows-and-more/

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - AWS CloudWatch Synthetic Service Introduction and Quick Tips To Start
ttan HackerNoon profile picture

AWS just released CloudWatch Synthetic service a few days ago.

The tool is to help you setup monitoring tool that can load web page, take screenshot or send API calls with auth token etc. It is part of the whole CloudWatch toolset so you can get all the nice web UI for the metrics and logs

This new service is built on Google’s puppeteer tools

https://github.com/puppeteer/puppeteer

It is quite easy to setup, details can be found here:

https://aws.amazon.com/blogs/aws/new-use-cloudwatch-synthetics-to-monitor-sites-api-endpoints-web-workflows-and-more/

Today, AWS X-Ray launches support for Amazon CloudWatch Synthetics, enabling developers to trace end-to-end requests…aws.amazon.com

Read more: Debugging with Amazon CloudWatch Synthetics and AWS X-Ray

From my experience these days trying to set it up for one of my customer. I found the service is quite easy to use and pretty powerful. Here are some of my findings:

  • Each of the tests is called a “Canary” and it is just a Nodejs(Puppeteer) lambda function script.You can set the “Canary” to run every a few minutes to generate nice time-series data.
  • Each successful run will leave a Blue dot and failed one will leave a Red dot
  • If you click on the dots, you can exam the screenshots, HAR Files (each js/css/assets file’s performance) and the lambda script’s log at that moment
  • You can set data retention for how many days to keep the metrics. For example I set to keep Success ones for 1 day and Failed ones for 7 days
  • It’s part of the whole CloudWatch services so it’s very easy to configure the alarms to send to SNS then you can send to PagerDuty or email subscriptions

Here is one of my script to monitor customer’s site. It simulates the login process and take screenshots before and after login.

var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');

const pageLoadBlueprint = async function () {

    // INSERT URL here
    const URL = "https://example.com";
    const username = "[email protected]";
    const passwd = "@#^!abcd1234"
    let page = await synthetics.getPage();
    const response = await page.goto(URL, {waitUntil: 'domcontentloaded', timeout: 30000});
    //Wait for page to render.
    //Increase or decrease wait time based on endpoint being monitored.
    await page.waitFor(10000);
    await page.type('input[name="email"][type="text"]', username)
    await page.type('input[name="password"][placeholder="Password"]', passwd)

    try {
        await synthetics.takeScreenshot("click", 'result');
    } catch(ex) {
        synthetics.addExecutionError('Unable to capture screenshot.', ex);
    }
    await page.click('span[class="sign-in-form__title"]')
    await page.waitFor(10000);
    await synthetics.takeScreenshot('loaded', 'loaded');
    let pageTitle = await page.title();
    log.info('Page title: ' + pageTitle);
    if (response.status() !== 200) {
        throw "Failed to load page!";
    }
};

exports.handler = async () => {
    return await pageLoadBlueprint();
};

I ran this Canary every 10 minutes so we can have a really good way to measure their site’s performance during the day.

The last thing to talks about is its pricing. Currently it’s $0.0012 per canary run (https://aws.amazon.com/cloudwatch/pricing/). So the Canary we setup will cost about $5 a month ( $0.0012 * 6 * 24 * 30). Not too bad :)

Hope this helps.

About me: I am an AWS certified DevOps Engineer and Solution Architect pro. I’m currently working for an AWS premium partner consulting company.

The blogs here are all my experience and my opinions. Hope you will find them helpful