Lab 7 · Lambda & Fargate¶
Performance · Est. time: 25–30 min · Cost: ✅ Lambda's free tier (1M requests + 400,000 GB-s/month) covers this easily. The optional Fargate task is a few cents.
Goal. Create a Lambda function with an execution role, invoke it, and understand where Lambda fits vs Fargate — the Compute Choices judgment.
Step 1 — Create a Lambda function¶
- Lambda → Create function → Author from scratch. Name
lab-fn, runtime Python 3.13. - Under permissions, let Lambda create a new execution role with basic Lambda permissions. Create function.
- Replace the code with:
Set the handler to
def handler(event, context): name = event.get("name", "world") return {"statusCode": 200, "body": f"Hello, {name}!"}lambda_function.handler(match the file/function name). Deploy.
The execution role is the point
The function gets its AWS permissions from its execution role — temporary credentials, no stored keys. To let it read DynamoDB/S3, you'd attach those permissions to this role (Topic 1).
Step 2 — Invoke it¶
Step 3 — See the limits that decide exam questions¶
On the Configuration → General configuration tab, note:
- Timeout — default 3s, max 15 minutes. Anything longer must run on Fargate/EC2/Batch.
- Memory — 128 MB–10 GB (CPU scales with it).
Try setting timeout to its max and observe the ceiling: 15 min. That single number rules Lambda in or out of many scenarios.
Step 4 (optional) — Where Fargate fits¶
You don't need to build a Fargate task to learn the distinction, but conceptually:
- If this workload were a long-running container (say a 40-minute job) or a persistent service, you'd run it on ECS/Fargate — serverless containers, no 15-minute cap, no servers to manage.
- Lambda = short, event-driven functions; Fargate = serverless containers.
(To actually try it: ECS → create a cluster → run a task on Fargate from a public image like
nginx, then stop it. It costs a few cents; stop the task promptly.)
Teardown¶
✅ What you should understand now¶
- A Lambda function runs from an execution role — temporary credentials, no stored keys.
- Lambda's hard limit is 15 minutes; longer or persistent work → Fargate/EC2/Batch.
- Lambda = serverless functions; Fargate = serverless containers — both scale without managing servers.
- You pay per request + duration, and it scales to zero when idle — ideal for spiky, event-driven work.
Related: Learn — Compute Choices