Lambda — Function as a Service
Lambda — Function as a Service
There is a model where code runs at the function level without provisioning a server. Compute wakes up when an event arrives, runs the function once, and disappears. AWS's seat for this is Lambda — it played a major role in popularizing the word "serverless."
1. About Lambda
| When | Event |
|---|---|
| 2014 | Lambda GA. |
| 2015 | API Gateway integration · VPC access. |
| 2019 | Provisioned Concurrency. |
| 2020 | Container Image support (10 GB). |
| 2021 | Graviton2 (ARM). |
| 2022 | Function URL · SnapStart (Java). |
Lambda units:
- Function — Handler + runtime + env vars + memory.
- Trigger — The event source that invokes the function.
- Layer — Shared dependencies across functions.
- Execution Role — IAM role used when the function calls other AWS services.
2. Event triggers
| Source | Example |
|---|---|
| API Gateway · ALB · Function URL | HTTP requests |
| S3 | Object upload · delete |
| DynamoDB Stream · Kinesis | Table changes · streams |
| SQS · SNS | Queue messages · notifications |
| EventBridge | Schedules · custom events |
| Cognito · IoT · CloudWatch Logs | Identity · devices · logs |
A function can connect to multiple triggers. The mode (sync, async, stream) varies by trigger.
3. Concurrency
Default account-region limit is 1000 (request to raise). Per-function reserved concurrency or provisioned concurrency tunes it.
Request → Lambda checks the execution container pool → reuse if available
→ otherwise create new (cold start)
4. Cold start
The latency of creating a new container. Hundreds of ms to several seconds depending on runtime, bundle size, and language.
| Runtime | Cold-start trend |
|---|---|
| Node.js · Python | Relatively short (hundreds of ms) |
| Go · Rust (custom) | Short |
| Java · .NET | Longer (seconds) |
Mitigations:
- Provisioned Concurrency — Pre-warm N containers. Extra cost.
- SnapStart (Java) — Boot from a post-init snapshot.
- Bundle slimming — Reduce dependencies.
- Frequent invocations — Containers within 5 ~ 15 minutes get reused.
5. Memory · CPU
Lambda allocates CPU proportionally to memory. Range 128 MB ~ 10240 MB. Increasing memory raises CPU and changes cost and speed together.
There are setups where the same cost runs faster (e.g., reports of 1024 MB being faster and cheaper than 256 MB).
6. Layer · Container Image
Layer — Shared dependencies and runtimes. Upload as ZIP and attach to functions. Up to 5 per function.
Container Image — Push an OCI image to ECR and run it as a Lambda function. Up to 10 GB. Useful when the standard ZIP 250 MB limit is too small for big dependencies or binaries.
FROM public.ecr.aws/lambda/python:3.12
COPY app.py ${LAMBDA_TASK_ROOT}
COPY requirements.txt ${LAMBDA_TASK_ROOT}
RUN pip install -r requirements.txt
CMD ["app.handler"]
Graviton2 (ARM) — Reports indicate roughly 20% lower price at the same memory. Verify dependency compatibility.
7. HTTP entry points
- API Gateway — Managed HTTP API gateway. REST API and HTTP API. HTTP API is newer (2020), with lower cost and latency.
- ALB — Application Load Balancer can also target Lambda.
- Function URL — A direct HTTPS endpoint attached to a function (2022). HTTP calls without API Gateway.
8. Comparison with other FaaS
| Platform | Model | Strengths | Limits |
|---|---|---|---|
| Lambda (2014) | FaaS | Rich integrations · IAM · VPC | Cold starts (varies by runtime) |
| Cloudflare Workers (2017) | V8 isolate | Very small cold starts (ms) | Runtime constraints (V8 only) |
| Vercel Functions (2018) | Node + Edge | Next.js integration | Vercel-bound |
| Cloud Run (2019) | Container-based | Free runtime · short cold starts | GCP-bound |
| Azure Functions (2016) | FaaS | .NET integration · Durable Functions | Cold starts |
| Fly Machines (2022) | microVM | Fast boot · container freedom | More microVM than FaaS |
Cloud Run runs containers per execution, with smaller cold starts and no runtime constraints, often cited as a different-flavored alternative to Lambda. Cloudflare Workers is V8-isolate-based with practically no cold starts but constrained Node compatibility.
9. Hello World (Python)
# handler.py
def handler(event, context):
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": '{"hello":"world"}',
}
zip -j fn.zip handler.py
aws lambda create-function \
--function-name hello \
--runtime python3.12 \
--role arn:aws:iam::123:role/lambda-exec \
--handler handler.handler \
--zip-file fileb://fn.zip
10. Pricing structure
- Requests — Per million invocations.
- GB-seconds — Memory × execution time (in ms, minimum 1 ms).
- Data transfer — Standard AWS traffic rules.
Monthly free tier (1M requests + 400K GB-seconds). Many small side projects fit within the free tier.
11. Where it fits, where it doesn't
Fits:
- Short backend tasks (under a few seconds).
- Processing after S3 uploads.
- Stream processing (SQS · Kinesis).
- Scheduled jobs (EventBridge).
- Webhook receivers.
Doesn't fit:
- Always-on long-running services.
- Large memory or GPU workloads.
- WebSocket servers.
- User-facing paths needing fast cold starts (consider Cloudflare Workers · Cloud Run).
12. Common pitfalls
Cold start inside VPC — VPC-attached functions used to have longer cold starts due to ENI creation. Improved after 2019, but a gap remains.
15-minute limit — A single execution maxes out at 15 minutes. Longer work splits into Step Functions · Fargate · ECS.
6 MB payload / 6 MB response limits — Large files go through S3.
/tmp 512 MB ~ 10 GB — Check the limit when processing large files.
Log cost — CloudWatch Logs gets surprisingly expensive. Watch output volume + retention.
DB connection floods — Creating DB connections per invocation exhausts the pool. Use RDS Proxy, an external pooler, or a serverless DB.
Idempotency — Async triggers (SQS, S3) can deliver the same message twice. Handle idempotency.
Closing thoughts
Lambda is nearly free for short event handling, but unsuitable for long-running workloads heavy on DB pools. Cold starts + 15-minute cap + payload limits are the base constraints — within them, it makes a very simple answer.
Next
- route53
- load-balancers
Lambda developer guide · Lambda pricing · SnapStart · Cloudflare Workers · Cloud Run · Vercel Functions · Azure Functions · SAM · CDK for reference.