
Building Vane: A Serverless AI Environmental Agent with AWS Lambda & boto3
Discover how we built Vane, an enterprise environmental operations agent, using a zero-hardware serverless architecture. This technical deep dive explores integrating FastAPI with AWS Lambda via Mangum, archiving telemetry to Amazon S3 using boto3, and leveraging AI for budget-aware facility decisions.
Most environmental dashboards suffer from a fundamental design flaw: they tell facility managers what happened, but leave them entirely on their own to figure out why it happened and what to do about it.
When a campus building experiences an 18% electricity consumption spike, a standard dashboard plots a graph. It doesn't tell you if the spike is isolated to evening hours, whether HVAC or lighting is the culprit, or which intervention fits within a strict ₹1 Lakh budget limit.
To solve this, we built Vane—an enterprise environmental operations agent that transforms passive data into cost-aware operational decisions. Here is a technical deep dive into how we architected Vane using Python, AWS open-source tooling, serverless patterns, and generative AI.
System Architecture
Vane is designed around a zero-hardware, serverless-ready architecture. The system ingests raw time-series telemetry, runs deterministic baseline calculations in Pandas, archives raw payloads to Amazon S3, and routes enriched context to an AI reasoning kernel.
React / Vite Frontend → Amazon API Gateway → AWS Lambda (FastAPI + Mangum) → Amazon S3 & AI Reasoning Engine
Key AWS Integration Highlights
1. Serverless FastAPI Execution with Mangum
Rather than deploying dedicated EC2 instances or container clusters for our backend, we engineered our Python FastAPI application to run serverlessly on AWS Lambda via API Gateway.
To achieve native ASGI compatibility on Lambda without modifying our FastAPI route logic, we used Mangum, an open-source adapter that translates API Gateway proxy events into standard ASGI HTTP cycles:
Python
from fastapi import FastAPIfrom mangum import Mangumapp = FastAPI(title="Vane Operations API")# Mangum wraps FastAPI for native AWS Lambda invocationhandler = Mangum(app)
This pattern allows us to test the backend locally using uvicorn while maintaining instantaneous, scale-to-zero serverless deployment capabilities on AWS.
- 2. Streamed Telemetry Archival via boto3
Compliance and audit trail requirements dictate that all ingested facility telemetry must be preserved in immutable object storage. We integrated the boto3 SDK to stream raw CSV payloads directly to Amazon S3 upon ingestion:
Python
import osimport boto3from botocore.exceptions import BotoCoreError, NoCredentialsErrorAWS_REGION = os.getenv("AWS_REGION", "us-east-1")S3_BUCKET_NAME = os.getenv("VANE_TELEMETRY_BUCKET", "vane-telemetry-storage")def archive_telemetry_to_s3(file_bytes: bytes, filename: str):"""Streams ingested telemetry directly to Amazon S3 via boto3."""try:s3_client = boto3.client("s3", region_name=AWS_REGION)s3_client.put_object(Bucket=S3_BUCKET_NAME,Key=f"telemetry/{filename}",Body=file_bytes)except (BotoCoreError, NoCredentialsError) as e:# Graceful fallback during offline / local developmentprint(f"[AWS SDK] Running in offline execution mode: {e}")
3. Declarative Infrastructure with AWS SAM
To ensure repeatable deployments across environments, we defined our infrastructure using the AWS Serverless Application Model (SAM) (
template.yaml ):YAML
AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31Description: Vane - Serverless Environmental Operations Agent StackGlobals:Function:Timeout: 30MemorySize: 512Resources:VaneApiFunction:Type: AWS::Serverless::FunctionProperties:CodeUri: backend/Handler: main.handlerRuntime: python3.11Events:ApiEvent:Type: ApiProperties:Path: /{proxy+}Method: ANYTelemetryStorageBucket:Type: AWS::S3::BucketProperties:BucketName: vane-telemetry-storage
Deterministic Anomaly Math + Agentic Reasoning
A critical architectural challenge was preventing AI hallucinations when processing large time-series datasets. We solved this with a hybrid deterministic-agentic pipeline:
- Pandas Baseline Math: Upon file upload, Pandas splits historical data (7-day baseline) from recent data (3-day evaluation window). It computes 24-hour moving average drift. If a building exceeds a 15% drift threshold, it triggers a
CRITICALstate.
- Temporal Context Injection: The backend extracts temporal features (e.g., Spike isolated between 18:00 and 22:00 in Block C) and injects this exact structured data into Gemini 3.8 Flash.
- Budget Constraints: When an operator provides a capital constraint (e.g., "I only have ₹1 Lakh"), the AI kernel evaluates market intervention costs, automatically disqualifies high-CAPEX interventions (like Rooftop Solar at ₹12L), and recalculates optimal operational priorities.
Key Learnings & Takeaways
- Serverless Portability: Using Mangum with FastAPI provided the best developer experience—allowing rapid local API iteration without sacrificing cloud-native Lambda deployment readiness.
- Graceful SDK Fallbacks: Implementing defensive execution paths around
boto3API calls ensured that local developer workflows remained uninterrupted even when offline, while keeping production S3 archival rock-solid.
- Hybrid Intelligence: Combining deterministic data engines (Pandas) with reasoning models (LLMs) eliminates hallucination risks in enterprise operational tools.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article