writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
serverless-debuggerDebug and optimize serverless functions (AWS Lambda, Vercel Functions, Cloudflare Workers). Use when someone asks to "debug Lambda", "trace serverless request", "fix cold starts", "analyze CloudWatch logs", "optimize Lambda performance", "reduce init duration", or "troubleshoot function timeout". Correlates logs across invocations and generates fixes.
Independent GitHub snapshot · Automated classification · Original documentation governs
This skill helps you trace, debug, and optimize serverless function invocations. It correlates logs across chained functions, identifies cold start bottlenecks, analyzes timeout patterns, and generates optimized configurations to reduce latency and failure rates.
When given CloudWatch logs, Vercel logs, or similar:
When given invocation metrics or asked to analyze cold starts:
Init Duration in CloudWatch or equivalentawait on promises (function exits before async work completes)Generate platform-specific configs:
Input: "My order-processor Lambda timed out at 14:32 UTC. Here are CloudWatch logs."
Output:
Request Trace — req-abc123
14:32:01.100 [api-gateway] Request received: POST /orders
14:32:01.203 [auth-handler] ✅ 15ms — Token validated
14:32:01.340 [order-processor] START — Warm invocation
14:32:01.355 [order-processor] Validating order payload... OK
14:32:01.412 [order-processor] Calling inventory-check (sync HTTP)
14:32:31.412 [order-processor] ❌ TIMEOUT (30s limit reached)
Cause: inventory-check function had a 28s cold start (256MB memory,
22MB bundle). order-processor's synchronous HTTP call waited for the
full cold start + execution, exceeding its 30s timeout.
Fix: Set inventory-check to 1024MB memory (reduces cold start to ~4s),
add provisioned concurrency of 1, or make the call async with SQS.
Input: "Our payment function has 5s cold starts. Here's the package.json and handler code."
Output:
Cold Start Diagnosis — payment-handler
Current: 512MB memory | 18.4MB bundle | Init P95: 4,900ms
Issues Found:
1. Imports entire AWS SDK v2: `const AWS = require('aws-sdk')` — adds 8MB
Fix: `import { DynamoDBClient } from '@aws-sdk/client-dynamodb'` — 400KB
2. Stripe SDK loaded at top level with full module
Fix: Lazy import inside handler: `const stripe = await import('stripe')`
3. 512MB memory = 0.33 vCPU — init is CPU-bound
Fix: Increase to 1024MB = 0.66 vCPU (init ~2x faster)
Projected After Fixes:
Bundle: 18.4MB → 2.1MB
Memory: 512MB → 1024MB
Init P95: 4,900ms → ~380ms
Monthly cost delta: +$3.20 (more memory but fewer retries)
serverless.yml changes:
payment-handler:
handler: src/payment.handler
memorySize: 1024
timeout: 15
architecture: arm64
provisionedConcurrency: 2
bundling:
minify: true
sourcemap: true
externalModules: []
node_modules bloatwebpack for Lambda — it's overkill; esbuild or rollup are better choices