Building AquaPin: Real-Time Urban Flood Resilience with AWS Serverless & Edge Computer Vision
Discover how AquaPin combines AWS Serverless (Lambda, DynamoDB TTL, API Gateway) with edge computer vision to build a real-time, self-healing urban flood intelligence map for commuter safety.
Every monsoon season, hundreds of vehicles stall, emergency response units face critical delays, and commuters are stranded because traditional municipal flood advisories lag by hours. Flash waterlogging is hyper-local and dynamic: municipal pumps or gravity drainage clear puddles in 45–90 minutes, yet static maps keep displaying outdated warnings long after the danger has passed.
To solve this, we engineered AquaPin — a crowdsourced, AI-verified waterlogging intelligence map powered by AWS Serverless architecture and edge computer vision.
🏗️ Architecture & Data Pipeline
AquaPin is designed around an event-driven serverless architecture that scales from zero cost during dry sunny days to thousands of concurrent reports during severe storm cloudbursts.
text
[Mobile PWA]│ (1) Live Camera Capture (`capture="environment"`)│ (2) Edge Computer Vision (Kovac/Peer Skin Rejection + Water Heuristics)▼[AWS HTTP API Gateway v2]│ (Low-latency routing & CORS preflight)▼[AWS Lambda (Node.js 20)]│ (Input validation, sanitized HTML entities, TTL calculation)▼[Amazon DynamoDB (PAY_PER_REQUEST)]│ (Automated background record decay via native TTL)▼[Leaflet Interactive Map UI]│ (Live consensus voting & emerald green self-healing markers)
🌟 Key Technical Innovations
1. Live Camera Anti-Spoofing & Edge Computer Vision
To prevent malicious actors from uploading recycled photos or internet memes:
- Enforced Camera Presence: AquaPin enforces native mobile camera triggers (
capture="environment"), verifying physical presence at the scene.
- Client-Side Edge Analysis: Before transmitting bytes across the network, the browser canvas analyzes raw pixel buffers using an optimized computer vision algorithm.
- Skin-Tone Rejection: It applies the Kovac / Peer skin-tone detection heuristic to immediately block selfies and portraits, while calculating turbidity and slate-sheen reflections. If flood water is absent, the submit button is locked at the edge — saving server bandwidth and expensive AI cloud calls.
2. Why DynamoDB Native TTL Solves Urban Flood Lag
Traditional mapping solutions rely on periodic cron jobs, scheduled Lambdas, or manual database deletion scripts to clear old alerts — incurring compute costs and maintenance overhead.
AquaPin utilizes Amazon DynamoDB Time-To-Live (TTL). Each pin calculates an
expiresAt epoch timestamp based on reported flood depth:- Ankle-deep (Caution): 30 minutes lifespan
- Knee-deep (Warning): 60 minutes lifespan
- Road Blocked (Danger): 90 minutes lifespan
DynamoDB scans and evicts expired records automatically in the background with zero read/write capacity units consumed and zero cron overhead.
💻 Infrastructure as Code (AWS SAM)
Our entire AWS cloud infrastructure is declaratively defined in a clean
template.yaml using the AWS Serverless Application Model (SAM):YAML
AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31Description: AquaPin - Serverless Backend for Real-Time Waterlogging AlertsResources:AquaPinTable:Type: AWS::DynamoDB::TableProperties:TableName: aquapin-pinsBillingMode: PAY_PER_REQUESTAttributeDefinitions:- AttributeName: pinIdAttributeType: SKeySchema:- AttributeName: pinIdKeyType: HASHTimeToLiveSpecification:AttributeName: expiresAtEnabled: truePostPinFunction:Type: AWS::Serverless::FunctionProperties:Runtime: nodejs20.xCodeUri: .Handler: lambdas/postPin.handlerPolicies:- DynamoDBCrudPolicy:TableName: !Ref AquaPinTableEvents:PostPinEvent:Type: HttpApiProperties:Path: /pinsMethod: post
🛡️ Production & Security Hardening
Before deploying, we implemented a full defense-in-depth security checklist:
- Zero-PII Storage Policy: No accounts, phone numbers, or user IDs are stored. Coordinates are precision-rounded to 5 decimal places to protect neighborhood privacy.
- Stored XSS Sanitization: All user comments and Leaflet HTML popups are sanitized with HTML entity escaping to neutralize script injection attacks.
- Anti-DoS Capping: Applied sliding-window rate limiting and enforced strict 5MB payload stream cutoffs.
👥 Self-Healing Community Consensus
During active rainfall, urban conditions change rapidly. AquaPin introduces a real-time consensus protocol: commuters passing by can tap "Water Cleared". When community confirmations reach consensus, the warning pin immediately transitions into an emerald green indicator showing "Road Clear — Safe to Traverse".
🔗 Try AquaPin
- Live Deployed App: https://aquapin.netlify.app
- GitHub Source Code: https://github.com/rabbitc0der/aquapin
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article