Skip to main content

Command Palette

Search for a command to run...

Automated Website Down Alert System🛑

Updated
•4 min read•View as Markdown
A

An enthusiastic and determined AWS Cloud learner looking for positions in the IT industry with the goal of enhancing career to secure a challenging position in a reputable organization to expand my learnings, knowledge, and skills AWS, Linux, Python

Hey everyone! I built a simple automated system to monitor my website 24/7. AWS CloudWatch triggers a Lambda function every 5 minutes to check the site’s status. If it’s down, the function sends an alert through AWS SNS via email or SMS.All activity is logged in CloudWatch logs creating a simple and reliable downtime alert workflow and I never have to manually check my site again!

AWS Serverless Website Monitoring – Step-by-Step Setup Guide

How it Worksâť“

This guide walks you through creating a fully serverless website monitoring system using:

  • Amazon SNS — for email alerts

  • AWS Lambda — to check website health

  • Amazon EventBridge (CloudWatch Schedule) — to run checks periodically

  • IAM roles and policies — to grant necessary permissions

When your website goes down, the Lambda function you deploy will automatically send an email notification.


🟦 1. Create SNS Topic for Email Alerts

This SNS topic will send you an email whenever your website becomes unreachable.

Steps

  1. Go to AWS SNS → Topics

  2. Click Create topic

  3. Type: Standard
    Name: website-down-alert

  4. Click Create topic

  5. Open the topic → Subscriptions → Create subscription

    • Protocol: Email

    • Endpoint: your email address

  6. Click Create subscription

  7. Check your inbox and Confirm subscription


🟦 2. Create IAM Role for the Lambda Function

The Lambda function needs permissions to write logs and publish SNS alerts.

Steps

  1. Go to AWS IAM → Roles

  2. Click Create role

  3. Trusted entity: AWS service
    Use case: Lambda

  4. Click Next

  5. Attach the policy:

    • AWSLambdaBasicExecutionRole (provides CloudWatch Logs access)
  6. Click Next

  7. Role name: lambda-website-checker-role

  8. Click Create role

Add SNS Publish Permission

  1. Open the newly created role

  2. Go to Permissions → Add permissions → Create inline policy

  3. Service: SNS

  4. Actions: Publish

  5. Resources:
    Choose Specific → paste your SNS topic ARN
    (from the SNS topic details page)

  6. Name the policy: SNSPublishAccess

  7. Click Create policy


🟦 3. Create Lambda Function to Check Website Status

This Lambda function will check your website and send an alert if the status is not 200 (OK).

Steps

  1. Go to AWS Lambda → Functions

  2. Click Create function

  3. Function name: website-up-checker
    Runtime: Python 3.12
    Architecture: x86_64
    Permissions:

    • Choose Use an existing role

    • Select lambda-website-checker-role

  4. Click Create function

Updated Lambda Code

In the Lambda Code editor, paste the following (after updating the two variables):

import urllib.request 
import boto3

# 🚨 Configuration Variables - UPDATE THESE 
# Replace YOUR_ACCOUNT_ID and AWS_REGION 
SNS_TOPIC_ARN = "arn:aws:sns:us-east-1:940482406743:website-down-alert" 
URL_TO_MONITOR = "https://httpstat.us/500" # Use a dummy URL for initial testing

def lambda_handler(event, context):
    try:
        # Check the URL, with a 5-second timeout
        response = urllib.request.urlopen(URL_TO_MONITOR, timeout=5)
        status = response.getcode()

        # Check if status is not the expected "UP" status (200)
        if status != 200:
            send_alert(f"Website returned unexpected status: {status}")
            return {"status": status}

        # If status is 200, the site is up, no alert is sent
        print(f"Website is UP, status: {status}")
        return {"status": status}

    except Exception as e:
        # Catch any exception (like timeout, connection error) and send alert
        send_alert(f"Website DOWN! Error: {str(e)}")
        return {"error": str(e)}

def send_alert(message):
    """Publishes a message to the specified SNS Topic."""
    sns = boto3.client("sns")
    sns.publish(
        TopicArn=SNS_TOPIC_ARN,
        Subject="🚨 Website Down Alert!",
        Message=f"Alert! {URL_TO_MONITOR} is DOWN.\n\nReason: {message}"
    )

Then click Deploy.


🟦 4. Schedule the Function Using EventBridge .

This triggers the Lambda function periodically to check the website.

Steps

  1. Go to EventBridge → Schedules

  2. Click Create schedule

  3. Schedule name: website-up-checker-schedule

  4. Schedule pattern: Recurring schedule

    • Rate: Every 5 minute (recommended)
  5. Click Next

  6. Target type: AWS service
    Select a target: Lambda function
    Function: website-up-checker

  7. Click Next, review, then Create schedule


🚀 Your Monitoring System Is Now Live

Because the test URL (https://httpstat.us/500) always returns 500, you should receive an immediate email alert.

Once confirmed:

  1. Return to the Lambda function

  2. Update URL_TO_MONITOR to your real website

  3. Click Deploy

Your system is now monitoring your site automatically.