AWS Lambda as the website monitoring tool.

AWS Lambda is a server less solutions to run some code without care about resources. You focus only on a logic of the function you want to run, the rest is on the AWS side. It’s possible to run function in periodic fashion or based on external events (CloudWatch).

Server less solutions are popular now because includes a lot of advantages. We don’t care about servers, operating systems etc. There is also cost savings aspect, you pay only for resources (like Memory) and time the function run. And what is most important, you pay only when function is executed.

Website Monitoring.

Im a lazy person, so that’s why I’m always looking for easiest way to solve something. In this case, I’ve got some small test environment. One EC2 instance with database and Wordpress stack on it. Let’s skip discussion about purpose of this design. Let’s assume this is mandatory design for this test environment. This architecture is without redundancy, so I decided to add monitoring option. Maybe in the future some self-healing capabilities also. In this post I will focus on how I used AWS Lambda and CloudWatch for website state monitoring.


The monitoring solutions should check particular URL and look for http code respond. I don’t won’t to do this directly from the server (like script and cron). I want to exclude potential server side issues. So I decided to do this on external resources and AWS Lambda fit this perfectly.

So how it works. For every few minutes Lambda verifies, if http code 200 is returned. In the next step the result is send to CloudWatch as custom metric. For simplifying, this custom metric can have this values:

In the next, there is an Alarm configured for this metric. If the metric value is lower than 200, the email notification will be send.

For simplicity and flexibility this solution is based on two Lambda functions:


So let’s jump into AWS Management Console.

On you can find a code of this functions.

To fire up this we need two IAM roles:

Now let’s create a functions. Skip all blueprints and remember about proper IAM roles.

Don’t forget about Source Event for WebsiteCheck function. I used CloudWatch Events – Schedule

As a final step we need to define Alarm and email notification for this custom metric.

How much is it cost?

I assumed the website will be check every 5 minutes. That gives 8640 executions per month with average execution time 500 ms. So the cost is zero USD! (First 1 million requests per month is free). To be sure check the lambda calculator (

Every client receives 10 CloudWatch metrics and 10 Alarms for free

“New and existing customers also receive 10 metrics (applicable to Detailed Monitoring for Amazon EC2 instances, Custom Metrics, or CloudWatch Logs*), 10 alarms, and 1 million API requests each month at no additional charge”

That’s it. I hope this idea will be useful for you.

This post appeared originally at my blog and was translated from Polish.

New tech geek, traveler, 🏃‍♂️ and 🏌️‍♂️Independent Cloud Consultant&Architect. Leader of AWSUG PL. AWS Community Hero

New tech geek, traveler, 🏃‍♂️ and 🏌️‍♂️Independent Cloud Consultant&Architect. Leader of AWSUG PL. AWS Community Hero