AWS - Website Monitor
Simple, near-zero-cost website monitoring which sends email alerts when a website outage is detected or resolved.
This monitor runs a Lambda Python function using an HTTP request to check if the website is online. Lambda is triggered by EventBridge, which I configured to trigger every 5 minutes. When an outage is detected, it pushes a message to an SNS topic. It monitors multiple sites & their online status by querying a DynamoDB table.
Required Resources in AWS
Lambda Function
Lambda is the core of this tool and runs our Python script which checks the online status of websites and generates the alert message to be sent out by SNS. One environment variable needs to be configured so Lambda knows where the look for the website information:
- TABLE_NAME: Name of your DynamoDB table
- dynamodb.GetItem
- dynamodb.PutItem
- dynamodb.UpdateItem
- dynamodb.Scan
DynamoDB Database
1 DynamoDB table stores website urls, SNS topic ARN to push alerts to, and current online status. Lambda requires an IAM role to be able to read & write to this table, allowing the following actions:
EventBridge
I used a Scheduled Rule in EventBridge to run the Lambda function every 5 minutes, however, you can change the interval to suit your needs.
SNS Topic(s)
SNS pushes website outage alerts to email or SMS recipients. In my case, I'm using e-mail. You can have one SNS topic per website.
Python Script
The core of the script relies on the 'requests' module to send HTTP/1.1 requests to the website to check if they're online. If an HTTP 200 response isn't sent or the request throws a Python exception then the website is determined to be offline.
Before checking the website status, first, we pull the DynamoDB table data so we can compare the 'is_down' value to see if the website was offline that last time we checked. This way we stop the script from sending an alert every 5 minutes while an outage is occurring. Also, this allows us to send an alert when the outage is resolved.
At the end, if the outage status has changed, we update the database to reflect this. This process repeats every 5 minutes.
Improvements
Firstly, I want to create a web app to go alongside this. The front-end would be simple, allowing for you to add/remove/change the websites being monitored in DynamoDB and view active outages. This will come with a lot of security considerations, though.
Currently, no outage history is being stored, however, keeping this logged in the database would make the tool more useful.
Always open to suggestions as well.