Here's a simple and cost-effective AWS architecture for web page monitoring that fits well within the free tier:
Architecture Overview
Core Components:
- AWS Lambda - Runs the monitoring logic
- S3 Bucket - Stores page snapshots for comparison
- EventBridge - Schedules periodic checks
- SNS - Sends email notifications
Implementation
Here's a Python Lambda function that handles the monitoring:
import boto3
import requests
import hashlib
from datetime import datetime
import difflib
import os
s3 = boto3.client('s3')
sns = boto3.client('sns')
BUCKET_NAME = os.environ['BUCKET_NAME']
URL_TO_MONITOR = os.environ['URL_TO_MONITOR']
SNS_TOPIC_ARN = os.environ['SNS_TOPIC_ARN']
def lambda_handler(event, context):
# Fetch current page content
response = requests.get(URL_TO_MONITOR)
current_content = response.text
current_hash = hashlib.md5(current_content.encode()).hexdigest()
# S3 key for storing snapshots
s3_key = f"snapshots/{URL_TO_MONITOR.replace('https://', '').replace('/', '_')}/latest.html"
hash_key = f"snapshots/{URL_TO_MONITOR.replace('https://', '').replace('/', '_')}/latest.hash"
try:
# Get previous content and hash
prev_obj = s3.get_object(Bucket=BUCKET_NAME, Key=s3_key)
prev_content = prev_obj['Body'].read().decode('utf-8')
hash_obj = s3.get_object(Bucket=BUCKET_NAME, Key=hash_key)
prev_hash = hash_obj['Body'].read().decode('utf-8')
# Compare hashes
if current_hash != prev_hash:
# Archive the old version with timestamp
timestamp = datetime.utcnow().strftime('%Y%m%d_%H%M%S')
archive_key = s3_key.replace('latest.html', f'archive/{timestamp}.html')
s3.copy_object(
Bucket=BUCKET_NAME,
CopySource={'Bucket': BUCKET_NAME, 'Key': s3_key},
Key=archive_key
)
# Generate diff
diff = '\n'.join(difflib.unified_diff(
prev_content.splitlines(),
current_content.splitlines(),
fromfile='previous',
tofile='current',
lineterm=''
))
# Save diff to S3 for grep analysis
diff_key = s3_key.replace('latest.html', f'diffs/{timestamp}.diff')
s3.put_object(Bucket=BUCKET_NAME, Key=diff_key, Body=diff)
# Send notification
message = f"""
Web page changed: {URL_TO_MONITOR}
Change detected at: {datetime.utcnow().isoformat()}
Diff saved to S3: s3://{BUCKET_NAME}/{diff_key}
You can analyze the changes using AWS CLI:
aws s3 cp s3://{BUCKET_NAME}/{diff_key} - | grep "your_pattern"
Or download both versions:
Previous: aws s3 cp s3://{BUCKET_NAME}/{archive_key} previous.html
Current: aws s3 cp s3://{BUCKET_NAME}/{s3_key} current.html
"""
sns.publish(
TopicArn=SNS_TOPIC_ARN,
Subject=f'Page Changed: {URL_TO_MONITOR}',
Message=message
)
except s3.exceptions.NoSuchKey:
# First run - no previous version exists
print("First run - storing initial snapshot")
# Save current version
s3.put_object(Bucket=BUCKET_NAME, Key=s3_key, Body=current_content)
s3.put_object(Bucket=BUCKET_NAME, Key=hash_key, Body=current_hash)
return {
'statusCode': 200,
'body': f'Checked {URL_TO_MONITOR} - Hash: {current_hash}'
}
Setup Steps
- Create S3 Bucket:
aws s3 mb s3://your-webpage-monitor-bucket
- Create SNS Topic:
aws sns create-topic --name webpage-changes
aws sns subscribe --topic-arn arn:aws:sns:region:account:webpage-changes \
--protocol email --notification-endpoint your-email@example.com
- Create Lambda Function:
- Runtime: Python 3.9+
- Timeout: 30 seconds
- Memory: 256 MB
- Environment variables:
- Create EventBridge Rule:
aws events put-rule --name webpage-monitor \
--schedule-expression "rate(1 hour)"
- Add Lambda Permissions:
The Lambda needs permissions for S3 (read/write) and SNS (publish).
Using grep for Analysis
When you receive a notification, you can analyze changes directly from S3:
# View the diff
aws s3 cp s3://your-bucket/snapshots/.../diffs/20240618_120000.diff - | less
# Search for specific patterns
aws s3 cp s3://your-bucket/snapshots/.../diffs/20240618_120000.diff - | grep "price"
# Compare any two versions
aws s3 cp s3://your-bucket/snapshots/.../archive/20240617_120000.html old.html
aws s3 cp s3://your-bucket/snapshots/.../latest.html new.html
diff old.html new.html | grep "pattern"
Free Tier Considerations
- Lambda: 1M free requests/month, 400,000 GB-seconds
- S3: 5GB storage, 20,000 GET, 2,000 PUT requests
- SNS: 1,000 email notifications/month
- EventBridge: Free for AWS service events
For hourly checks on one page, you'll use about 720 Lambda invocations/month, minimal S3 storage, and only send emails when changes occur - well within free tier limits.
This architecture is simple, serverless, and scales easily if you want to monitor multiple pages later.