Key | Value |
---|---|
Services | S3, API Gateway, Lambda, SQS, Dynamodb, EventBridge |
Integrations | AWS SDK, AWS CLI |
Categories | Serverless, Scheduler Lambda, Worker Lambda, Lambda function URLs, LocalStack developer endpoints, queues JavaScript, Python, htmx |
Level | Beginner |
This project demonstrates a simple uptime monitor service using AWS services emulated by LocalStack. The service allows users to add, remove, and monitor the uptime of websites. The system regularly checks the availability of the websites and stores the results in DynamoDB, providing a simple frontend hosted on S3 for interaction.
The project architecture consists of several AWS services, emulated locally using LocalStack:
- DynamoDB: Stores URLs and their statuses (UP/DOWN).
- SQS (Simple Queue Service): Queues requests to check website statuses.
- AWS Lambda:
- Uptime Scheduler: Periodically triggers checks for all registered websites.
- Uptime Worker: Processes SQS messages and pings websites to determine their status.
- API Lambdas: Provide the ability to add, remove, and retrieve URLs via an API.
- API Gateway: Exposes the API to interact with the URLs (add, remove, retrieve) through HTTP requests.
- S3: Hosts the frontend dashboard that interacts with the API to manage URLs.
Here's the web application in action:
uptime-monitor-using-LocalStack-demo.webm
This project runs entirely in your local environment, using LocalStack to simulate AWS services.
The system works as follows:
- Frontend (hosted on S3) allows users to add, remove, and view the status of websites.
- API Gateway routes requests from the frontend to the Lambda functions.
- DynamoDB stores URLs, their statuses, and the last checked timestamp.
- Scheduler Lambda triggers every minute to scan the URLs stored in DynamoDB and sends each URL to an SQS queue.
- Worker Lambda listens to the SQS queue, pings each URL, and updates its status in DynamoDB.
- Docker: Install Docker from here.
- LocalStack: Install LocalStack using the instructions here.
- AWS CLI: Install the AWS CLI from here.
- Python 3.8+ installed locally for running the Lambda functions.
- Clone the repository:
git clone git@github.com:Rakanhf/uptime-monitor-localstack.git
cd uptime-monitor-localstack
Create a virtualenv and install all the development dependencies there:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt
Start LocalStack Pro with the appropriate CORS configuration for the S3 Website:
LOCALSTACK_AUTH_TOKEN=... localstack start
Set up AWS services (S3, DynamoDB, SQS, API Gateway, Lambda) in LocalStack:
bash setup.sh
This script will:
- Create a DynamoDB table for storing URLs.
- Create an SQS queue for website checks.
- Deploy Lambda functions (Scheduler, Worker, API handlers).
- Set up API Gateway to expose the API.
- Upload the frontend to an S3 bucket and configure it for static website hosting.
http://my-static-site.s3-website.localhost.localstack.cloud:4566/