This is the source code for the "Building Programs" blog by Robert J. Brotherus.
- Architecture: Server-Side Rendered (SSR) AWS Lambda function
- Languages: ClojureScript compiled to Node.js
- Infrastructure: AWS Lambda + API Gateway + Terraform
- Build tools:
shadow-cljsfor ClojureScript compilation - Dependencies:
- Server-side rendering with plain HTML generation
- Markdown parsing with
markedlibrary - Syntax highlighting with
highlight.js
The blog is now a server-side rendered application running on AWS Lambda, replacing the previous SPA architecture. This provides:
- Better SEO: Search engines can crawl the fully rendered HTML
- Faster initial page loads: No client-side JavaScript required
- Simplified deployment: Single Lambda function handles all routes
- Cost-effective: Pay-per-request serverless model
├── src/brotherus/blog/
│ ├── lambda.cljs # Main Lambda handler
│ ├── server_render.cljs # Server-side rendering functions
│ ├── filters.cljs # Article filtering logic
│ └── ...
├── infrastructure/
│ └── main.tf # Terraform configuration
├── resources/public/
│ └── images/ # Static images
├── target/lambda/ # Compiled Lambda function
├── deploy-lambda.ps1 # Main deployment script
├── build-lambda.ps1 # Build script
└── shadow-cljs.edn # ClojureScript build configuration
- JDK 8 or later - Required for ClojureScript compilation
- Node.js - Required for npm dependencies and Lambda runtime
- AWS CLI - Required for deployment to AWS
- Terraform - Required for infrastructure management
-
Install dependencies:
npm install
-
Interactive Development (Recommended):
# Start both ClojureScript watch build and development server npm run dev # or use PowerShell script: .\dev-lambda.ps1
This will start:
- File watcher that rebuilds lambda on source changes
- Local development server at http://localhost:3003
- Shadow-cljs status page at http://localhost:9630
-
Manual Development:
# Start file watcher in one terminal: npm run watch-and-build # Start development server in another terminal: npm run dev-server
-
Test locally without server:
node test-lambda.js # or test specific routes: node test-lambda.js --filter=post
-
Configure AWS credentials:
aws configure
-
Deploy Lambda function:
./deploy-lambda.sh # or skip infrastructure updates: ./deploy-lambda.sh --skip-infra -
Test deployment:
# Test specific routes node test-lambda.js --filter=page
The blog is deployed my deploy-lambda.ps1 script (using Terraform main.tf) to create resources up to and including the API Gateway. This makes the app available at: *https://358i0ec26g.execute-api.eu-north-1.amazonaws.com/
On top of that we have manually created CloudFront distribution and Route53 alias record mapping to https://www.brotherus.net In addition to providing nice URL, CloudFront provides caching and compression. Without caching, the lambda can be slow with long articles, up to 18 sec for Infia article! But CloudFront cache returns even that in ~300ms (and ~20 ms if in local cache). X-Cache response header tells if CloudFront cache was used. CachePolicy default ttl is 24 hours. Cloudfront item can be invalidated at: https://us-east-1.console.aws.amazon.com/cloudfront/v4/home?region=eu-north-1#/distributions/E13505H1AVUV02/invalidations/create
- Server-side rendering for better SEO and performance
- Markdown support with syntax highlighting
- Responsive design with clean, readable layout
- Tag-based filtering for organizing posts
- Serverless architecture for cost-effective hosting
For detailed deployment information, see README-LAMBDA.md.