Serverless Best Practices
A condensed summary of the 25 most important serverless practices for Node.js teams on AWS Lambda - drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important serverless practices for Node.js teams on AWS Lambda - drawn from every page in this section.
Duration p99 and Errors rate per function aliasStateless handlers: No in-memory session state across invocations - Serverless Basics.
Externalize state: DynamoDB, RDS, ElastiCache, S3 - not global variables for user data.
Init-phase client reuse: DynamoDB/S3/SSM clients in module scope - @aws-sdk v3.
Parse env with Zod at init: Fail fast on misconfiguration before taking traffic.
Async handlers only: No callback-style handlers in new TypeScript code - Lambda Handler Patterns.
callbackWaitsForEmptyEventLoop = false: When using DB pools or HTTP keep-alive agents.
Return 4xx, do not throw: Validation errors should not retry async invocations.
Idempotent SQS consumers: Dedupe with DynamoDB conditional writes on messageId or business key.
SQS partial batch failures: Report batchItemFailures for poison messages only.
Use SDK v3 modular imports: Never add aws-sdk v2 to new projects.
esbuild bundle application code: Minify + tree shake - Cold Start Mitigation.
Target zip under 5-15 MB: Investigate bloat with visualizer.
nodejs24.x runtime: Match local Node 24 LTS.
Prefer arm64 (Graviton): Benchmark native deps in CI matrix.
Right-size memory: More memory grants more CPU; speeds init and execution.
Timeout from p99 + margin: Include downstream calls; avoid hard kills mid-write.
VPC only when required: Accept ENI cold start cost or use RDS Proxy / Data API.
Provisioned concurrency on aliases: Not on $LATEST; cost-control with autoscaling policies.
Structured JSON logs: Include awsRequestId and business correlation ids.
No PII in logs: Redact bodies; log ids only.
Secrets from SSM/Secrets Manager: Cached at init; never in env in console screenshots.
Framework adapters for migration only: Plan slim handlers for hot paths - serverless-express / aws-lambda-fastify.
IaC for every function: SAM, CDK, or Terraform - no click-ops drift.
Separate functions per trigger type: HTTP vs SQS vs schedule - do not multiplex unrelated events.
Revisit Lambda vs ECS quarterly: Steady traffic may be cheaper on Fargate - Platform Deploy Basics.
Reuse AWS SDK clients and parsed configuration in module scope (init phase). It cuts per-invocation overhead on every warm call.
When p99 latency, WebSockets, execution time over 15 minutes, or baseline cost exceeds always-on containers at your traffic level.
Many small functions when bundles, timeouts, or IAM permissions differ. One function with internal router only for small APIs and prototypes.
Unit test handlers with fixture events. Integration test with SAM local or deploy to a dev stack. Do not rely only on console test button.
No. Same quality gates and artifact promotion as containers - CI/CD Best Practices.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 19, 2026