DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • A Guide to Using Amazon Bedrock Prompts for LLM Integration
  • The Future of Rollouts: From Big Bang to Smart and Secure Approach to Web Application Deployments
  • Automate Application Load Balancers With AWS Load Balancer Controller and Ingress
  • Running Legacy SAP Versions on AWS

Trending

  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • The Role of Retrieval Augmented Generation (RAG) in Development of AI-Infused Enterprise Applications
  • Recurrent Workflows With Cloud Native Dapr Jobs
  • STRIDE: A Guide to Threat Modeling and Secure Implementation
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Monitoring and Observability
  4. Application Monitoring Using CloudWatch Synthetics

Application Monitoring Using CloudWatch Synthetics

In this article, I will explain how Cloud watch synthetics are used to monitor your application using AWS synthetics canaries and why it is needed.

By 
Manjeet Kaur user avatar
Manjeet Kaur
·
Jul. 13, 23 · Opinion
Likes (4)
Comment
Save
Tweet
Share
5.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will explain how CloudWatch synthetics are used to monitor your application using AWS synthetics canaries and why it is needed.

Imagine you have already invested significant resources in building a robust application infrastructure on Amazon Web Services (AWS). However, with the increasing complexity of your application and the ever-growing number of users, ensuring a seamless user experience has become a challenge. To address this challenge, you have a powerful monitoring solution offered by AWS called Synthetics. Along with this, customers also want to ensure sensitive data is detected and masked consistently across all their logs. With account-level policies, customers will be able to protect all their logs in a simplified and consistent way. This includes data monitoring as well as part of application monitoring.

Synthetic monitoring is an approach to run automated scripts and simulate user behavior to identify and fix the website availability, performance, and functionality issues before end users notice them.

With the CloudWatch synthetic feature, you can create different kinds of canaries to continually verify your customer experience even when you do not have traffic, monitor and test for unusual behavior, and trace issues for faster resolution.

Using Canaries, you can discover issues with your website before your customer do. 

What Are CloudWatch Synthetics/Canaries?

CloudWatch synthetic feature was introduced in November 2019. It helps users monitor the application endpoint more easily. It runs tests on your endpoints 24/7 and alerts you if they don’t behave as expected. Using this feature, you can create canaries (configurable scripts) that run on a schedule to monitor applications.

Canaries are small, modular, lightweight pieces of code that simulate user interaction with your application. These can be written in Node.js or Python, and they work over both HTTP and HTTPS protocols.

Canaries use a headless Google Chrome Browser to perform tasks like opening web pages and taking screenshots. It uses Google’s Puppeteer library to perform the tests with Node.js, and the Selenium framework is used with Python.

Canaries scripts can be customized to check for availability, latency, transactions, broken or dead links, step-by-step task completions, and page load errors in your application.

CloudWatch Synthetics supports monitoring your REST APIs, URLs, and website content, checking for unauthorized changes from phishing, code injection, and cross-site scripting.

Architecture

The architecture of CloudWatch synthetics is defined as follows:

  • Synthetics is an orchestration service that offers a simple and effective configuration interface to continuously verify customer-facing application performance. 
  • Endpoints are monitored using a canary, implemented as an AWS Lambda function
  • The Lambda function exposes a standard interface through which you inject some NodeJS code. This code is responsible for performing the “endpoint configuration” authentication and then validating the responses. 
  • You can also store responses to an S3 bucket and generate alarms for any value that falls beyond the pre-configured thresholds.

Here is a reference diagram for the general architecture of CloudWatch Synthetics.

Here is a reference diagram for the general architecture of CloudWatch Synthetics

Cost

The pricing for Amazon AWS synthetic monitoring follows the pay-as-you-go concept just like many other AWS services. No minimum charges are levied.

Charges are incurred when you exceed 100 canary runs per month using CloudWatch Synthetics. To reduce cost, you should delete unnecessary canaries — sample pricing for N. Virginia region is as below. These costs do not include the S3 storage, CloudWatch alarm, or Lambda execution costs.

Note: Cost may vary for other regions.

Configure Amazon CloudWatch

Security Consideration

When creating and running a canary, you should consider security issues and follow the best practices: 

  • Secure Connection: Use encrypted connections that start with https://.
  • Secret Manager: Do not store sensitive information in canary code. Use a secret manager to keep your secret safe.
  • Log Data Protection: Detect and Mask sensitive data in Logs
  • IAM Roles: Create a canary with an IAM execution role that allows the least privileges or permission.

How To Create Canary

Canaries can be created using prebuilt blueprints or by creating custom canaries with CloudFormation templates.

Blueprints

You can create canaries by using ready-made code snippets using the blueprint option from the AWS management console. There are six types of blueprints available, and you can choose one among them according to your use case.

1. Heartbeat Monitoring

Heartbeat Monitoring loads the specified URL and stores the page’s screenshot and the HTTP archive file to monitor the URL’s status, duration, and failure reason. You can also use a Heartbeat Monitoring blueprint to monitor multiple URLs if you use syn-nodejs-puppeteer-3.1 or a later runtime version.

2. API Canary

With the API Canary, you can monitor read and write methods such as GET, POST, PUT, and DELETE of REST API. The API Canary blueprint also supports multi-step canaries, which monitor your APIs as HTTP steps. You can test multiple APIs in a single canary, but each step will be a separate request that can access a different URL. You can prevent sensitive data from being recorded by not capturing headers and response bodies. 

3. Broken Link Checker

A broken link checker canary is used to address the problem of broken links on websites. You can enter the starting point (URL) and the number of links to be checked. With this blueprint, you can check the following errors:

  • 404 Page Not Found
  • Bad URL
  • Invalid Host Name
  • Invalid HTTP response code
  • The host server returns empty responses.
  • The HTTP requests time out during the canary’s run.
  • The host consistently drops connections.

4. Visual Monitoring

Visual monitoring is used to monitor visual defects in your web application. This visual monitoring blueprint compares screenshots taken during a canary run with screenshots from a baseline canary run. 

5. Canary Recorder

The Canary Recorder blueprint enables the use of the CloudWatch Synthetics Recorder. The Synthetics Recorder is a Google Chrome Extension that help you to create canaries faster and easier. This records your click and type actions on the application and automatically generates a Node.js script.

6. GUI Workflow

GUI Workflow Builder Canary blueprint allows you to define test steps on your web applications. Below are the actions that you need to specify before using this blueprint:

Click — Selects the specified element and simulates a user clicking

Verify selector — Verifies that the element that you have specified exists on the webpage.

To verify in a Node.js script, you can specify an element using the format: [id=] or a[class=]. To verify in a Python script, you can specify an element using the format: xpath //*[@id=] or //*[class=].

Verify text — Verifies that the mentioned string is contained within the target element.

Input text — Writes the text that you have specified in the target element.

Click with navigation — Waits for the whole page to load after selecting the specified element.

Create Canary

Pre-Requisite:  For demo purposes, I have deployed the pet-store API using this link.

Go to Cloudwatch -> Application Monitoring and select Synthetics Canaries.

Synthetics Canaries

Create API Canary.

 Create API Canary

Select option “I am using an API gateway,” choose API, and then stage. CloudWatch Synthetics lists all the API endpoints and their stages in the current Region.

Canary builder

Select test API and the hostname will be automatically populated.

hostname

api-canary

Configure the HTTP steps that the canary uses to monitor API endpoints.

Configure the HTTP steps that the canary uses to monitor API endpoints

HTTP request details

pets

cat

show optional query strings

reporting configuration

post method

request data

reporting configuration

get method

api-get-petID

script editor

Schedule Canary

Schedule Canary

Configure other configuration parameters as “Data Retention, Storage, Access Permission.”

Configure other configuration parameters as “Data Retention, Storage, Access Permission.”

create a new role

CloudWatch alarm can be configured while creating canaries or can be set up later as well.

CloudWatch alarms

Synthetics can be integrated with X-Ray to debug and find the root cause of failure.

active tracing

Canary is created.

stats

api-canary

Go to canary -> availability section, expand the HTTPS requests configured, and verify the response.

Go to canary -> Availability section, expand the HTTPS requests configured, and verify the response

GET

POST

GET

canary artifacts and S3 location

In the monitoring section, CloudWatch metrics for synthetics monitoring are displayed.

monitoring

CloudWatch metrics

canary steps duration

contd metrics

synthetics

Alert Notifications

When a canary fails to obtain the expected result from the website or API endpoint, notifications are sent through CloudWatch Alarms and SNS. You can set up an alarm on the synthetic console wizard while creating synthetic canaries, or it can be set up later. You can configure SNS-topic to get the notification to your email inbox or incident response tooling (e.g., ServiceNow).

That is Amazon CloudWatch Synthetics in a nutshell.

Summary

In summary, AWS Synthetics provides a proactive and customizable monitoring solution by simulating user interactions with critical endpoints and workflows. Its integration with AWS RUM (Real-User Monitoring), extensive monitoring capabilities, serverless architecture, and seamless integration with other AWS services make it a powerful choice for monitoring application availability and performance. Additionally, its cost-effective pricing model adds value to organizations looking for efficient monitoring solutions.

AWS Synthetic monitoring application

Opinions expressed by DZone contributors are their own.

Related

  • A Guide to Using Amazon Bedrock Prompts for LLM Integration
  • The Future of Rollouts: From Big Bang to Smart and Secure Approach to Web Application Deployments
  • Automate Application Load Balancers With AWS Load Balancer Controller and Ingress
  • Running Legacy SAP Versions on AWS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!