Platform: AWS Lambda + CloudFront + S3 | Runtime: Node.js 20.x on ARM64 | Not supported: PHP, WebSockets, native modules without layers, persistent processes
Architecture
- Static assets are built and uploaded to S3, served via CloudFront CDN (global edge locations)
- Automatic HTTPS with wildcard certificate
- URL rewriting for clean routes (
/about→/about/index.html) - Cache: HTML 1 min, CSS/JS 5 min
- Each API route becomes a Lambda function with its own URL
- SSR pages are bundled with the server runtime
Resource Limits
| Resource | Default | Maximum | Notes |
|---|---|---|---|
| Memory | 256 MB | 10,240 MB | Higher memory = faster CPU |
| Timeout | 30 seconds | 900 seconds (15 min) | SSR uses 60s default |
| Bundle Size (zipped) | - | 50 MB | Larger uses S3 upload |
| Bundle Size (unzipped) | - | 250 MB | AWS Lambda hard limit |
| Request Payload | - | 6 MB | Use S3 presigned URLs for larger |
| Response Payload | - | 6 MB | Stream large responses |
| Ephemeral Storage (/tmp) | 512 MB | 10,240 MB | Cleared between invocations |
| Environment Variables | - | 4 KB total | Use Secrets Manager for large |
| Concurrent Executions | 1,000 | Depends on quota | Per-account AWS limit |
| ZIP Import (upload) | - | 1 GB | Max 10,000 files |
Do’s and Don’ts
- Do
- Don't
- Use pure JavaScript packages —
bcryptjs,pg(pure mode),josefor JWT - Keep functions small — split large APIs into separate files for faster cold starts
- Use environment variables — store secrets in Hiveku’s env vars, not in code
- Optimize bundle size — use dynamic imports, tree-shaking, avoid bundling dev deps
- Use S3 for large files — generate presigned URLs for uploads over 6MB
- Return proper status codes — use 200, 201, 400, 401, 404, 500 appropriately
- Set cache headers — use Cache-Control for static responses
- Handle cold starts — initialize DB connections outside the handler
API Routes
Where to Place API Files
Hiveku auto-detects API routes from these directories:File to URL Mapping
| File Path | Deployed URL |
|---|---|
api/users.ts | /api/users |
api/users/[id].ts | /api/users/:id |
api/files/[...path].ts | /api/files/* (catch-all) |
app/api/auth/route.ts | /api/auth |
API Handler Formats
Hiveku supports two function formats — use whichever you prefer:- Web API Format (Recommended)
- AWS Lambda Format
Modern format, similar to Next.js/Vercel Edge Functions:
| Feature | Web API Format | AWS Lambda Format |
|---|---|---|
| Export | export default function | export async function handler |
| HTTP Method | req.method | event.httpMethod |
| Query Params | req.query.id | event.queryStringParameters?.id |
| Request Body | req.body (auto-parsed) | JSON.parse(event.body) |
| Response | Response.json(data) | { statusCode, body, headers } |
hiveku.json Configuration
Create ahiveku.json in your project root to customize deployment:
| Field | Description |
|---|---|
functions.directories | Additional directories to scan for API routes |
functions.include | Specific files to include as functions |
functions.exclude | Glob patterns to exclude |
functions.routes | Override auto-generated URL paths |
functions.config | Per-function memory/timeout settings. Use ** for defaults |
build.outputDirectory | Custom build output directory |
build.env | Build-time environment variables (NEXT_PUBLIC_*) |
Advanced Features
Lambda Layers
Auto-provisioned layers for native dependencies. These packages just work when you add the layer:sharp bcrypt argon2 canvas prisma ffmpeg puppeteer
Scheduled Functions (Cron)
Add a@schedule comment or put files in a cron/ directory:
cron(min hour day-of-month month day-of-week year)
| Expression | Description |
|---|---|
cron(0 9 * * ? *) | 9 AM daily |
cron(0 */2 * * ? *) | Every 2 hours |
cron(0 9 ? * MON-FRI *) | 9 AM weekdays |
cron(0 0 1 * ? *) | 1st of month |
rate(5 minutes), rate(1 hour), rate(1 day), rate(7 days)
Streaming Responses
SSE and chunked responses for AI apps. Auto-detected fromtext/event-stream content type:
Package Compatibility
- Works
- Needs Replacement
- Next.js Only
| Package | Use For |
|---|---|
prisma | ORM (use connection pooling + keep-alive for serverless) |
pg / mysql2 | Database drivers (pure JS mode) |
bcryptjs | Password hashing (pure JS) |
jose | JWT signing/verification |
zod | Schema validation |
axios / node-fetch | HTTP clients |
@aws-sdk/* | AWS services (S3, SES, etc.) |
stripe | Payment processing |
resend / nodemailer | Email sending |
openai | AI/LLM integration |
Code Patterns
Database Connection (Prisma)
Initialize the Prisma client outside the handler so connections are reused across Lambda invocations. Use connection pooling and keep-alive pings to avoid cold reconnect latency.JWT Authentication
Large File Upload (S3 Presigned URL)
Custom CORS Headers
Reusable Auth Middleware
Environment Variables
Auto-Injected Variables
These are available in every Lambda function automatically:Build-Time vs Runtime
NEXT_PUBLIC_*variables are bundled at build time and exposed to the browser- All other variables are available only at runtime, server-side only
Troubleshooting
Function timeout (30s limit)
Function timeout (30s limit)
Check if you’re hitting the 30s default timeout. Increase in
hiveku.json, or optimize your code. Database queries without connection pooling are a common cause.Bundle too large
Bundle too large
Use dynamic imports, check for accidentally bundled devDependencies, exclude large assets. Consider splitting into multiple functions.
Native module error
Native module error
You’re using a package with native bindings (
bcrypt, sharp, etc.). Switch to a pure JS alternative or request a Lambda Layer.CORS errors
CORS errors
Hiveku adds CORS headers automatically. If you still see errors, check your frontend is calling the correct URL and your API returns proper response format.
Environment variable undefined
Environment variable undefined
Make sure the variable is set in Hiveku dashboard.
NEXT_PUBLIC_* vars need a redeploy to take effect. Server-side vars are only available in Lambda, not the browser.Slow cold starts
Slow cold starts
Reduce bundle size, increase memory (more memory = faster CPU), minimize top-level imports. Consider keeping functions warm with scheduled pings.
Too many database connections
Too many database connections
Lambda can scale to many instances. Use a connection pooler (Supabase, PlanetScale) or set your pool size to 1-2 connections per function.
Files disappear from /tmp
Files disappear from /tmp
Lambda
/tmp is ephemeral. Files may persist between invocations on the same instance but will be cleared. Use S3 for persistent storage.