# AWS Lambda and Serverless Best Practices for Production

URL: https://www.devopsness.com/blog/aws-lambda-and-serverless-best-practices-for-production
Author: Kiril Urbonas
Published: 2025-09-22
Updated: 2025-09-22
Categories: Cloud
Tags: AWS, Terraform, CI/CD

Summary: Design serverless apps for reliability, cold start, and cost. Event-driven patterns and observability.

---
# AWS Lambda and Serverless Best Practices for Production

Serverless fits event-driven and variable load. Use these practices to keep it reliable and cost-effective.

## Cold Start and Performance

- **Provisioned concurrency** for latency-sensitive paths (or warm-up jobs).
- **Right-size memory** (more memory = more CPU); benchmark to find the sweet spot.
- **Minimize package size**: Tree-shake, avoid large deps; use layers for shared code.

## Reliability

- **Idempotency**: Use a idempotency key (e.g. in DDB) for critical actions.
- **Dead-letter queues**: Send failed events to DLQ; alert and replay.
- **Retries**: Use Lambda retries with backoff; set **max retries** and **reserved concurrency** to avoid thundering herd.

## Cost

- **Measure** cost per invocation and per request in dashboards.
- **Reserved concurrency** to cap cost and avoid noisy neighbors.
- **Right-duration**: Short timeouts for quick work; longer only when needed.

## Observability

- **Structured logs** and **trace IDs**; send to CloudWatch Logs Insights or a third-party.
- **Metrics**: Invocations, errors, duration, throttles; alarm on error rate and latency.

Best practice: treat Lambda as a building block; design event contracts and failure modes up front.
