AWS Builder Center
Weekend Creative Agent Challenge: MedLex — The Clinical Broad-Sheet

Weekend Creative Agent Challenge: MedLex — The Clinical Broad-Sheet

MedLex is a lightning-fast, vintage-newspaper style medical dictionary that acts as a clinical search agent. It features real-time typeahead and automatically generates context-aware anatomical illustrations based on your search terms using a secure serverless AWS Lambda backend.

Weekend Creative Agent Challenge: MedLex — The Clinical Broad-Sheet
Tags: #agents #serverless #aws #architecture #frontend
Vision: An Agent That Brings Anatomy to Life
What if looking up complex medical terminology didn't feel like navigating a clunky, ad-heavy, early-2000s webpage? What if, instead, it felt like reading a premium, beautifully typeset vintage medical journal that intelligently anticipated your needs?
That is the vision behind MedLex. It is a serverless clinical search agent that combines the stark, elegant aesthetic of a classic newspaper broadsheet with the speed of a modern AI-driven application.
I didn't just want a search bar that returned text. I wanted an agent that understands the clinical context of your search and dynamically curates the UI to match it. If you search for a heart condition, the page shouldn't just define it—it should instantly transform to display vintage anatomical artwork of the human heart, perfectly matching the aesthetic of the page.

What It Does

MedLex acts as a real-time, context-aware clinical agent with four main capabilities:
  1. Thinks Ahead (Real-time Typeahead): As you type (e.g., "bra..."), the frontend agent instantly anticipates the most likely medical term ("bradycardia") and provides a ghost-text hint directly behind your cursor. A quick tap of the  Tab  key autocompletes the thought.
  1. Visualizes Context: When the search query is executed, the agent analyzes the clinical term. If it detects keywords related to major organs (like  cardiac ,  neuro ,  pulmonary , or  hepatic ), it automatically injects highly detailed, AI-generated vintage anatomical ink drawings into the reading pane.
  1. Speaks Every Word (Audio Pronunciation): It securely proxies requests to the Merriam-Webster Medical API to fetch not just the definition and etymology, but the exact clinical audio pronunciation. It renders a subtle, animated play button so you can hear the precise pronunciation of every single word you learn.
  1. Curates Autonomously (Word of the Day): A separate background agent ( daily_spotlight_agent.py ) wakes up every morning via Amazon EventBridge, uses Amazon Bedrock (Nova Lite) to discover a fascinating, obscure medical term, and automatically publishes it to the top of the website as the "Clinical Word of the Day"—so there is a new word to learn every single day without any manual effort.
┌────────────────┐ ┌───────────────┐ ┌───────────────┐ ┌────────────────┐
│ EventBridge │────▶│ Lambda Agent │────▶│ Amazon Bedrock│────▶│ Amazon S3 │
│ (Daily Trigger)│ │ (Python 3.12) │ │ (Nova Lite) │ │ (spotlight.json)│
└────────────────┘ └───────────────┘ └───────────────┘ └────────────────┘

Architecture Overview

To keep the application lightning-fast, highly secure, and within the AWS Free Tier, I opted for a 100% serverless architecture using Amazon S3 and AWS Lambda.
┌─────────────────────────────────────────────────────────────────┐
│ MedLex App │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────────────┐ │
│ │ Amazon S3 │ │ AWS Lambda │ │
│ │ (Static Website) │─────────▶│ (Python 3.12) │ │
│ │ │ │ │ │
│ └──────────────────┘ ┌──────────────────────────┐ │
│ │ │ 1. Parse & Sanitize │ │
│ │ │ 2. Attach Secret API Key │ │
│ │ │ 3. Fetch from Dictionary │ │
│ │ │ 4. Format JSON Response │ │
│ ▼ └──────────────────────────┘ │
│ ┌──────────────────┐ │ │
│ │ Frontend UI │ │ │
│ │ • Typeahead │◀──────────────────────┘ │
│ │ • Image Injector │ │
│ └──────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
AWS Services Used:
  • AWS Lambda (Python 3.12): Acts as the secure middleman agent for the dictionary search, and runs the autonomous daily spotlight agent.
  • AWS Lambda Function URL: Provides a direct, HTTPS endpoint for the frontend to hit, complete with native CORS configuration (bypassing the need for a heavy API Gateway).
  • Amazon S3: Hosts the static HTML, custom CSS grid, JavaScript, and the vintage image assets.
  • Amazon EventBridge: Triggers the daily spotlight agent every morning automatically.
  • Amazon Bedrock: Powers the AI agent to generate the fascinating Word of the Day content.

How I Built It

Step 1: The Secure Proxy Agent

I could not securely call the external dictionary API directly from the browser without exposing my private API key. So, I built a Lambda function to act as a secure proxy.
import json
import os
import urllib.request
import urllib.parse
MW_BASE = "https://www.dictionaryapi.com/api/v3/references/medical/json/"
def lambda_handler(event, context):
# Safely extract the search term
params = event.get("queryStringParameters") or {}
term = (params.get("term") or "").strip()
if not term:
return {"statusCode": 400, "body": json.dumps({"error": "Missing term"})}
# Attach the hidden environment variable
api_key = os.environ.get("MW_API_KEY", "")
encoded_term = urllib.parse.quote(term, safe="")
url = f"{MW_BASE}{encoded_term}?key={api_key}"
# Execute the secure request
req = urllib.request.Request(url, headers={"User-Agent": "MedLex/1.0"})
with urllib.request.urlopen(req, timeout=8) as response:
data = json.loads(response.read().decode("utf-8"))
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps(data)
}
Note: Because I enabled CORS natively in the AWS Lambda Function URL configuration, I didn't need to manually inject  Access-Control-Allow-Origin  headers into the Python response!

Step 2: Context-Aware Visual Injection

I used an AI image generator to create stunning, black-and-white engraved illustrations of the human heart, brain, lungs, liver, kidneys, and stomach.
I then wrote a frontend JavaScript agent function that analyzes the incoming search term and dynamically injects the appropriate artwork:
function renderCard(term, definition) {
let imgHtml = "";
const t = term.toLowerCase();
// The agent maps clinical terminology to the correct anatomical art
if (t.includes("heart") || t.includes("cardiac") || t.includes("bradycardia")) {
imgHtml = `<img src="vintage_heart.jpg" class="vintage-illustration">`;
} else if (t.includes("brain") || t.includes("cerebr") || t.includes("neuro")) {
imgHtml = `<img src="vintage_brain.jpg" class="vintage-illustration">`;
}
return `
<div class="card-content">
<div class="text-data">
<h2>${term}</h2>
<p>${definition}</p>
</div>
${imgHtml}
</div>
`;
}

Key Decisions & Challenges

Challenge: The Double-CORS Disaster Initially, the live search kept failing with a mysterious "Failed to Fetch" error. Upon inspecting the network tab, I realized the browser was rejecting the response because it contained two  Access-Control-Allow-Origin: *  headers. I had manually written the header into my Python Lambda code, but I had also toggled CORS on in the AWS Function URL settings. The Fix: I learned that if AWS is handling CORS at the Function URL level, you must strip CORS headers out of your application code to prevent duplication!
Decision: Enterprise Security on a Static Site Even though it's just a static HTML file on S3, I implemented strict enterprise security. I added a  Content-Security-Policy  (CSP) meta tag to explicitly whitelist my Lambda URL and block all malicious cross-site scripting (XSS) attempts.

What I Learned

  1. Serverless is unmatched for proxy layers: AWS Lambda is incredibly fast for building secure middleman APIs. It spins up, hides the API keys, handles the request, and shuts down instantly.
  1. EventBridge + Lambda = Autonomous Agents: Building the Daily Spotlight taught me how easy it is to schedule AI tasks using EventBridge, making the app feel alive even when nobody is managing it.
  1. UI Architecture matters: Taking the time to build a custom CSS grid (rather than using Tailwind or Bootstrap) allowed me to create a highly specific, editorial newspaper layout that makes standard API data feel like a premium experience.
  1. Keep it simple: I didn't need React, Node.js, or a complex database. Vanilla JS + S3 + Lambda is a powerhouse stack for lightweight agents.

What's Next

I'm planning to expand the agent's capabilities by adding:
  • "Clippings" (Bookmarks): Allowing users to save and bookmark complex terms to  localStorage  to build a personalized study guide.
  • Night Shift: A dark mode design to reduce eye strain during late-night clinical study sessions.

Links



Building MedLex proved that you don't need massive frameworks to build intelligent, context-aware agents. Sometimes, a beautiful UI and a perfectly configured AWS Lambda are all you need to bring data to life.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article