Lambda is wonderful, but it is not a silver bullet. Like any tool, it has technical limits and there are situations where using it is a bad idea (anti-patterns). We close the chapter by learning to recognize when Lambda is not the right answer: knowing this will save you headaches and make you a better architect.

The Technical Limits of Lambda

Lambda imposes a series of restrictions. You don't need to memorize exact numbers (they change over time), but you do need to know what is limited:

Limit Approximately Why it matters
Maximum execution time 15 minutes A function can't take longer; after 15 min, it is cut off
Memory Up to several GB Also defines the CPU it receives
Package size Limited (ZIP) That's why layers or container images are used
Temporary storage Limited space in /tmp For temporary files during execution
Concurrency There's a maximum per account Thousands in parallel, but not infinite

The most important limit to remember is the 15-minute one: a Lambda function cannot run for more than 15 minutes. If your task takes longer, Lambda is not the tool.

Anti-Patterns: When NOT to Use Lambda

An anti-pattern is using a tool for something it wasn't designed for. These are the cases where Lambda doesn't fit:

  1. Very Long Tasks

If a process takes more than 15 minutes (processing a huge video, a scientific calculation, a massive data migration), Lambda will cut it off halfway.

Better alternative: containers (ECS/Fargate, Chapter 17), EC2 instances, or batch processing services. For long workflows made up of short steps, you can orchestrate several Lambdas with Step Functions (Chapter 28).

  1. Applications with Constant, Very High 24/7 Traffic

Lambda is great for intermittent or unpredictable traffic (you only pay for usage). But if you have huge and constant traffic 24 hours a day, billions of executions can end up more expensive than a group of servers always on.

Better alternative: EC2 with Auto Scaling (Chapter 13) or containers, which at very high constant volume can be more economical. (It's worth doing the math: it depends a lot on the case.)

  1. In-Memory State Between Requests

Lambda is stateless: each invocation can run in a different environment, and you can't rely on memory being preserved between calls. If your application needs to keep data in memory between requests (a user session in RAM, a persistent local cache), Lambda is not suitable.

Better alternative: store the state outside the function, in services designed for it: DynamoDB (subchapter 8.3), ElastiCache (subchapter 8.4), or S3 (Chapter 5). This is, in fact, the correct way to design: state goes to an external service, not in the function.

  1. Connections to Traditional Relational Databases at Scale

Since Lambda can create thousands of executions in parallel, each trying to open a connection to a relational database (RDS, Chapter 8), it can exhaust the available connections and bring down the database.

Better alternative: use RDS Proxy (which manages and reuses connections), serverless databases like Aurora Serverless (subchapter 8.2) or DynamoDB, which scale better with Lambda.

  1. When Cold Starts Are Unacceptable and Constant

If you need ultra-low and guaranteed latency on every request, and cold starts (subchapter 14.4) are a constant problem even with provisioned concurrency, maybe an always-on service is better.

Table: Lambda Yes or No?

Your situation Lambda? Alternative if not
Short task, intermittent traffic ✅ Yes
Process events (S3, queues, DB changes) ✅ Yes
Light API/backend ✅ Yes
Task longer than 15 minutes ❌ No ECS/Fargate, EC2, Step Functions
Constant, very high 24/7 traffic ⚠️ Depends EC2/containers (do the math)
In-memory state between requests ❌ No DynamoDB, ElastiCache, S3
Always guaranteed ultra-low latency ⚠️ Depends Always-on service

The Right Mindset

Lambda doesn't replace servers: it's another tool in your toolbox. A good architect combines services: use Lambda for event processing and short tasks, containers or EC2 for constant and long workloads, and managed services (DynamoDB, S3, queues) for state and data.

The key question is not "Should I use Lambda?", but "Which tool fits this specific job best?". Sometimes it's Lambda, sometimes not, and many real architectures use several at once.

What You Should Remember

  • Lambda has limits: the most important is the 15-minute maximum execution time; there are also limits on memory, package size, temporary storage, and concurrency.
  • Anti-patterns (when NOT to use Lambda): tasks of more than 15 min, constant, very high 24/7 traffic, need for in-memory state between requests, and poor handling of connections to relational databases at scale.
  • State should go outside the function (DynamoDB, ElastiCache, S3): Lambda is stateless.
  • Alternatives depending on the case: ECS/Fargate or EC2 (long/constant tasks), Step Functions (long workflows by steps), RDS Proxy / Aurora Serverless / DynamoDB (databases at scale).
  • The right question is "Which tool fits this job best?", not "Should I use Lambda for everything?".

You've finished Chapter 14 and mastered the fundamentals of serverless! In Chapter 15 we'll look at the pieces that connect all these functions and services: messaging and events (SQS, SNS, EventBridge), key to building decoupled systems.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved