# Build a Serverless Website Uptime Monitor with AWS and AI

## Introduction

Hey everyone! Want to dip your toes into cloud computing without feeling overwhelmed? Let’s build something cool: **A serverless website uptime monitor using AWS.**

Imagine a tool that checks if a site’s up or down every 5 minutes, logs the results, and emails you with a little AI magic thrown in, all for free with AWS’s Free Tier. I’m talking about automation, alerts, and even sentiment analysis (like, is the news good or bad?). Whether you’re new to AWS or just curious about Cloud Operations, this project’s your perfect starting line.

## What You’ll Build

So, what are we making? A slick system that:

* Checks a website’s status every 5 minutes (up if it loads, down if it flops).
    
* Logs everything in CloudWatch so you can peek under the hood.
    
* Emails you the result of the status, like “Site’s down!”—with AI guessing if it’s a happy or sad update.
    

We’ll use **AWS Lambda** to run the code without servers, **EventBridge** to schedule it, **SNS** to send emails, and **Comprehend** to add that AI twist. It’s all about Cloud Operations basics, automation and monitoring with a fun modern edge. Here’s the flow:

```plaintext
Website → Lambda → CloudWatch Logs + SNS + Comprehend → Email
```

## Prerequisites

Before we jump in, you’ll need:

* AWS Free Tier account (grab one at [aws.amazon.com/free](https://aws.amazon.com/free)).
    
* Node.js on your computer (download it from [nodejs.org](http://nodejs.org) — super quick).
    
* Basic JavaScript know-how
    

No AWS experience? No worries—this is built for beginners like you. Let’s get started!

## Step-by-Step Guide

### Step 1: Set Up Your AWS Environment

First, head to [https://console.aws.amazon.com](https://console.aws.amazon.com) and sign into the AWS Console. Don’t have an account? Sign up at [https://aws.amazon.com/free](https://aws.amazon.com/free) — it’s free with the Free Tier, so no cost surprises. This is your cloud playground where all the magic happens. Log in, and you’re ready to roll!

![AWS Console homepage after login](https://cdn.hashnode.com/res/hashnode/image/upload/v1740154353135/517a40fd-372b-4470-91f8-7b33939e37ae.png align="center")

### Step 2: Create an SNS Topic for Alerts

Next, let’s set up email alerts. In the AWS Console, search for “SNS” (Simple Notification Service)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740167075113/28c88f0b-af2e-4d57-af94-593bbf67a356.png align="left")

* Click on “**Topics**” on the left navigation menu &gt; Click on “**Create topic**“
    
* Under **Type,** Select “**Standard**“
    
* Name it `WebsiteUptimeAlerts`, leave other options at default, and hit “**Create topic**”
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740167459295/092bc022-eb20-4bfd-a09c-2c839fb23761.png align="center")
    
* On the new page, click “**Create subscription,**” under Protocol, choose “**Email**” as the protocol, type your email address, and click on “**Create subscription**”. Check your inbox for a confirmation link—click it to activate. `SNS is like a delivery service for your app updates, dropping off messages wherever they're needed!`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740167947106/0cb15d51-5cc4-41d6-a990-3a5fac1668cc.png align="center")
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740168220939/194f4118-48b4-484f-8bae-0281e643073a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740168261697/740c9152-d180-4a2e-a430-4be3ed1a6a1b.png align="center")

### Step 3: Create and Upload the Lambda Function

Time to build the brains of our monitor! Locally, open your terminal (or command prompt), make a folder called `uptime-checker`, navigate to the folder and run this command:

```bash
npm init -y && npm install axios aws-sdk
```

This command creates a new Node.js project with a `package.json` file and then immediately installs the `axios` library for making HTTP requests and the `aws-sdk` for interacting with AWS services. This sets the stage for building a Node.js application that can perform HTTP actions and use AWS cloud resources.

Now, create a file `index.mjs` inside your project folder and save the code below to it.

```javascript
import axios from 'axios';
import AWS from 'aws-sdk';

const sns = new AWS.SNS();
const comprehend = new AWS.Comprehend();

export const handler = async (event) => {
    const url = 'https://reelbuzznow.com'; // Our test “up” site
    const topicArn = 'arn:aws:sns:us-east-1:YOUR_ACCOUNT_ID:WebsiteUptimeAlerts'; // Swap with your SNS ARN

    let message;
    try {
        const response = await axios.get(url, { timeout: 5000 });
        if (response.status === 200) {
            message = `Success: ${url} is up! Status: ${response.status}`;
        } else {
            message = `Warning: ${url} returned status ${response.status}`;
        }
    } catch (error) {
        message = `Error: ${url} is down! Reason: ${error.message}`;
    }
    return await sendAlert(message, topicArn);
};

async function sendAlert(message, topicArn) {
    const sentimentParams = { Text: message, LanguageCode: 'en' };
    const sentimentResult = await comprehend.detectSentiment(sentimentParams).promise();
    const fullMessage = `${message}\nSentiment: ${sentimentResult.Sentiment}`;
    const snsParams = { TopicArn: topicArn, Message: fullMessage };
    await sns.publish(snsParams).promise();
    return { status: 'Alert sent', message: fullMessage };
}
```

This code snippet checks if a website is up or down and sends an alert via SNS, including a sentiment analysis of the message. It uses `axios` to fetch the website, `AWS.SNS` to send notifications, and `AWS.Comprehend` to analyze the sentiment of the alert message. If the site is up, it sends a success message; if it's down or returns an error, it sends an error message. The `sendAlert` function then publishes this message (with sentiment analysis) to an SNS topic. Short and sweet: it's a website watchdog that barks (sends an alert) when there's a problem!

Rember to replace `YOUR_ACCOUNT_ID` with your AWS account ID (find it in the console under “My Account”) and the ARN from your SNS topic. or simple copy the ARN under your Topic.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740169118463/12208e88-b01b-43a6-97fa-cf748f9209b7.png align="center")

Next up, we need to ZIP up the following files for deployment `index.mjs`, `package.json`, and the `node_modules` folder together—call it [uptime-checker.zip](http://uptime-checker.zip). You can do this by simply creating a folder and copying the files into this folder or by entering the commands below on your terminal or command prompt where you have the initial folder:

```bash
zip -r uptime-checker.zip index.mjs package.json node_modules
```

Finally for this step, in the AWS Console search, search for **Lambda**.

* Click on “Create function,” &gt; name it **UptimeChecker**,
    
* Under Runtime, leave it at default Node.js 22x, and hit “Create function.”
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740169942612/451f22bf-f3d1-4a33-87fc-340b9905e3a2.png align="center")
    
* To upload your ZIP folder containing our code, click on the “Upload from” &gt; “.zip file,” &gt; select upload and select the zip folder from your local machine &gt; click on “Save” to upload and deploy the function.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740170116447/7f30ba06-a9a2-4a66-b0c3-cf967dd55597.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740171066937/2390f2ba-0c7a-45ae-a16d-bf7eb14c1c20.png align="center")
    
* **Lambda takes care of the servers so you can focus on the fun part: writing code! It's serverless bliss.**
    

### Step 4: Schedule with EventBridge

Now, let’s automate it.

* Search for “**EventBridge**” in the AWS console, click on “Schedules” (under “Scheduler”)
    
* And click on “Create schedule.” Name it TriggerUptimeChecker
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740172462917/b52a2777-f84e-434e-af46-6b36d2c0cd13.png align="center")
    
* Under Schedule pattern, choose “Recurring schedule”
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740172578020/2a23b981-b573-4cff-830f-f05ae21780de.png align="center")
    
* Under Schedule type, Select “Rate-based schedule” &gt; Rate: value 5: Unit: minutes “5 minutes” (or use cron: `0/5 * * * ? *` ). And turn off Flexible time window
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740171866404/b2e68f0e-037d-41b3-b3b9-ad78ad04b676.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740171896140/7f44c459-1497-4e96-be46-77a39fedef14.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740172034071/e9cb4475-80e9-4f3b-8259-5f31045f64f6.png align="center")
    
    * Click “Next“ &gt; For the Target API, pick “**Templated targets**” then “**AWS Lambda**” and select **UptimeChecker** under the Lambda function Invoke session Hit “Next.” till you get to the Review window, review and click on “**Create schedule**“
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740172504967/54c2b7c3-8ce9-4e93-b5de-e6525154892f.png align="center")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740172683171/a2b741ff-f1cd-4f0a-b2c5-42287cb233a4.png align="center")
        
        **EventBridge** is the ultimate matchmaker for your apps. It helps them chat and work together seamlessly, even when you're sleeping!
        

### Step 5: Grant Permissions

Our Lambda function needs permission to talk to other AWS services (SNS and AmazonComprehend). To grant these specific permissions, Go to our Lambda function &gt; **UptimeChecker** &gt; click on the “**Configuration**” tab &gt; click on “**Permissions**,” and click the role name.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740173057925/74936ebc-41c1-4175-b4d0-799944d4c365.png align="center")

In the IAM console opened in a new window, click on “Add permissions“ &gt; “Attach policies”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740173225337/ec5a4f91-a069-4164-a58e-556ad85fb1fc.png align="center")

On the permission policies window, search for and check each of these policies:

* AWSLambdaBasicExecutionRole (for logging).
    
* AmazonSNSFullAccess (for emails).
    
* ComprehendFullAccess (for AI).
    

Click on “**Add permissions**” to save it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740173441132/fae7b696-f731-40e1-8224-52b8332fbbd6.png align="center")

Think of this as giving Lambda the keys it needs to get the job done!

### Step 6: Test It

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740173658205/bf3e069c-3c1a-49ec-b7c4-903e6901c38f.gif align="center")

Let’s see it work! In the Lambda function, go to UptimeChecker &gt; “Test,” create a test event (name it TestDown, use an empty {} or leave the default Event JSON), and run it by clicking on “Test”. Check the result—it should say “**Site is up**”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740173934729/e98e4239-f80f-4a8b-9f48-9d8013dc7155.png align="center")

We’re getting this because the website URL in our function is heathy and up. Now let's change that.

* Go the Lambda function, go to UptimeChecker &gt; “Code,”
    
* Change the variable URL on line 30 from `“`[`https://reelbuzznow.com`](https://reelbuzznow.com)`“` to `“`[`http://this-site-does-not-exist.com`](http://this-site-does-not-exist.com/)`“`.
    
* Click on Deploy
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740174349648/5d3cbadf-fd16-46f7-a7ba-2e1bde21bfc7.png align="center")
    
    Now let’s re-run the test, got to the “Test“ tab, click on test — the result should say:  
    “Alert sent.”, “Error: [http://this-site-does-not-exist.com](http://this-site-does-not-exist.com) is down  
    Reason: xxxxxxxxx, “Sentiment: Negative” for our fake site.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740174704764/c5b2ba47-d227-4747-97e8-5968230a7541.png align="center")
    
    Wait for 5 minutes for EventBridge to kick in. Then, peek at Your inbox, you should get an email every 5 minutes with the status and sentiment—like “Sentiment: Negative” for our fake site.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740175074210/21d0bec3-f2f3-40e9-a986-60ff7552432f.png align="center")
    

### Step 7: Clean Up

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740175229925/d63843ca-7bfe-418d-84b3-37807b36e491.gif align="center")

**Done playing?**

You've built, you've tested, you've conquered! Now, let's keep things lean and mean. Time to decommission: `UptimeChecker` Lambda function, `TriggerUptimeChecker` EventBridge schedule, and `WebsiteUptimeAlerts` SNS topic. A clean cloud is a happy cloud (and a happy wallet!). — just good cloud habits! 😎

### Troubleshooting Tips

Hit a snag? Here’s help:

* **No logs in CloudWatch?** Check the EventBridge rule’s enabled and the Lambda role has AWSLambdaBasicExecutionRole.
    
* **No emails?** Confirm your SNS subscription (check your inbox/spam) and match the topicArn in the code.
    
* **Want to test a down site?** Swap the URL to `http://this-site-does-not-exist.com` see “NEGATIVE” alerts!
    

### What You’ve Learned

Look at you—you’ve nailed some serious skills:

* Running code without servers using Lambda.
    
* Automating tasks with EventBridge.
    
* Sending alerts with SNS.
    
* Adding AI smarts with Comprehend.
    
* Core Cloud Operations: automation, monitoring, and alerting.
    

All with Free Tier tools. You’re basically a cloud wizard now! Let’s keep the cloud vibes rolling — see you next time! 😉😏😜

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740175842051/3d6eadb9-d207-40c4-b350-ee906eee1b90.gif align="center")
