AWS Lambda Serverless Tutorial

AWS Lambda Serverless Tutorial

Introduction

Serverless is the most misunderstood word in cloud computing. It does not mean there are no servers — it means you do not manage them. With AWS Lambda you write a function, give it a trigger, and AWS runs it when the trigger fires and charges you for the milliseconds it used. No servers to patch, no capacity to plan, no bill when nothing runs.

This tutorial builds your first Lambda function in Python, triggers it, and explains the four things every beginner gets wrong: pricing, timeouts, cold starts and limits. You need an AWS account and the basics from our AWS Tutorial for Beginners — EC2, S3 and IAM. The Python in this tutorial is deliberately simple; our Python for DevOps tutorial covers the language side in depth.

Important update (28 Nov 2026): on 19 November 2026 AWS doubled the Lambda timeout from 15 minutes to 30 minutes (1,800 seconds) for on-demand Event Functions. Older tutorials — and older search results — still say 15 minutes. They are out of date.

What Lambda Is and When to Use It

A Lambda function is a piece of code plus its configuration: the runtime, the memory, the timeout, the permissions, and the trigger — the event that causes it to run. Triggers are everywhere in AWS: an HTTP request through API Gateway, a file uploaded to S3, a message on an SQS queue, a row written to DynamoDB, a schedule from EventBridge. The function runs, does its work, and stops. AWS handles the servers, the scaling and the availability.

Lambda fits workloads that are event-driven and short-lived: processing an uploaded image, responding to an API call, transforming a file, reacting to a database change, running a scheduled cleanup job. It fits badly for long-running processes, workloads that need a persistent local state, or anything that must run continuously — those belong on EC2, ECS or Fargate. The test is simple: if the work has a clear beginning and end and is triggered by an event, Lambda is probably right.

AWS now describes three Lambda form factors: Event Functions (the classic model, triggered by events), Web Functions (for HTTP workloads, with a 15-minute timeout), and MicroVMs (for longer work, up to 8 hours per MicroVM). This tutorial covers Event Functions, which is what most people mean by Lambda.

Your First Function

Create a function in the AWS console: Lambda → Create function → Author from scratch. Name it hello-lambda, choose the Python 3.14 runtime, and leave the defaults. The console gives you a code editor with a starter function — replace it with this:

import json

def lambda_handler(event, context):
    name = event.get("name", "world")
    return {
        "statusCode": 200,
        "body": json.dumps({"message": f"Hello, {name}!"})
    }

Every Lambda function has a handler — the function AWS calls, here lambda_handler — which receives two arguments: event, the data that triggered the function (a dictionary), and context, an object with runtime information such as the remaining time and the request ID. The handler returns a dictionary; for HTTP triggers, statusCode and body are the response.

Test it from the console with a test event — {“name”: “DevOps”} — and the execution result shows the return value, the duration and the billed duration. Then trigger it for real with an HTTP request: add an API Gateway trigger (or a function URL, the simpler option the console offers), and open the URL in a browser. You have just deployed an API with no server.

Runtimes — Which Language and Version

Lambda supports managed runtimes for Python, Node.js, Java, .NET, Go and Ruby, plus custom runtimes. As of 28 November 2026 the current versions are Python 3.14, Node.js 24, Java 25 and .NET 10, all on Amazon Linux 2023 and available on both x86_64 and arm64. Python 3.13, Node.js 22 and Java 21 are also supported. Node.js 26 and Python 3.15 are in public preview only — do not use them for production.

Two practical notes. First, each runtime has a deprecation date — Python 3.14 is supported until 30 June 2029, for example — and AWS retires old runtimes, so pin a current one and check the runtimes page when you start a project. Second, arm64 (AWS Graviton) functions cost about 20% less than x86_64 for the same work and are a one-line change in the function configuration; there is no reason not to use them for new functions.

Pricing — What It Actually Costs

Lambda pricing has two parts: requests and duration. The free tier gives you 1 million free requests and 400,000 GB-seconds of compute per month, every month. Beyond that, requests cost $0.20 per million and duration costs $0.0000166667 per GB-second. Duration is the function’s runtime multiplied by its memory allocation, rounded up to the nearest millisecond.

A worked example: a function with 512 MB of memory that runs 200 ms per invocation, called 5 million times a month. Duration per call is 0.2 seconds × 0.5 GB = 0.1 GB-seconds; 5 million calls is 500,000 GB-seconds. Subtract the 400,000 free GB-seconds and the 1 million free requests, and the bill is roughly 100,000 × $0.0000166667 + 4,000,000 × $0.20/1,000,000 — about $1.67 + $0.80, under $2.50 for the month. That is why Lambda is cheap for sporadic workloads and expensive for constant ones: a function running continuously costs far more than a small EC2 instance doing the same work. The free tier makes learning free; the pricing model makes the architecture decision for you.

Timeouts, Memory and Limits

Every Lambda function has a timeout, a memory allocation and a set of limits. Getting these right is most of operating Lambda.

Timeout. The default is 3 seconds — far too short for most real work, and the single most common cause of a first function “failing for no reason”. For Event Functions the maximum is now 30 minutes (1,800 seconds) as of 19 November 2026. Web Functions stay at 15 minutes. Set the timeout to slightly more than your function’s slowest realistic run, not to the maximum: a function that hangs should fail fast, not burn money for half an hour.

Memory. From 128 MB to 10,240 MB, in 1 MB increments. CPU scales with memory — roughly 1 vCPU at 1,769 MB — so increasing memory also makes the function faster, up to a point. The cheapest configuration is rarely the smallest one: a function that runs twice as fast at twice the memory costs the same, and finishes sooner. AWS’s own guidance is to test with different memory sizes and pick the cheapest point on the curve.

Package and size limits. A deployment package is 50 MB zipped for direct upload and 250 MB unzipped including layers. Larger dependencies go in layers (up to 5 per function, 4 KB of environment variables in total) or in a container image — Lambda supports container images up to 10 GB uncompressed. The /tmp directory is writable, from 512 MB to 10,240 MB, but it is per-invocation storage: do not treat it as permanent.

Concurrency. By default an account can run 1,000 concurrent executions per Region, and a single function can scale by 1,000 execution environments per 10 seconds. New accounts start with lower limits that rise automatically with usage. If your function is triggered by a burst — a thousand files landing in S3 at once — Lambda scales to meet it, which is both the feature and the risk: a runaway trigger can generate a large bill, so set reserved concurrency on functions with expensive downstream effects.

Cold Starts — the One Thing Everyone Asks About

A cold start is the delay when Lambda runs your function for the first time in a while: AWS must start an execution environment, load your runtime and code, and then run the handler. For Python and Node.js it is usually tens to low hundreds of milliseconds; for Java and .NET it can be seconds. Subsequent invocations reuse the warm environment and start immediately.

In practice, cold starts matter far less than tutorials suggest. They matter for latency-sensitive APIs with sporadic traffic — a user-facing endpoint called once an hour will cold-start often. They barely matter for event processing, scheduled jobs or internal tools. If they do matter, the fixes in order are: use a lighter runtime (Python or Node.js rather than Java), keep the deployment package small, and use provisioned concurrency — pre-warmed environments that AWS keeps ready for you, charged by the hour. Measure first, with CloudWatch logs showing the Init Duration of each invocation, before optimising.

From One Function to a System

A single function is a demo; a system is several functions connected by events. The standard pattern is: API Gateway receives a request and calls a function; the function writes to DynamoDB; a DynamoDB stream triggers a second function that processes the write; failures go to a dead-letter queue (an SQS queue that collects events a function could not process). Each piece is small and testable, and the failure of one does not take down the others.

Two disciplines make this work. First, make functions idempotent — running the same event twice should have the same effect as running it once — because Lambda can retry a failed invocation, and a non-idempotent function will double-charge a customer or double-send an email. Second, give each function the least-privilege IAM role it needs: a function that reads from one S3 bucket should not be able to delete from all of them. The role is created with the function, and tightening it later is harder than scoping it correctly at the start.

FAQ

Is AWS Lambda really free?

For learning, yes: 1 million requests and 400,000 GB-seconds per month are free, every month. Small personal projects usually stay inside the free tier entirely.

What languages can I use with Lambda?

Python, Node.js, Java, .NET, Go and Ruby as managed runtimes, plus custom runtimes for anything else. Python and Node.js are the most common choices for beginners.

What is the maximum time a Lambda function can run?

30 minutes for on-demand Event Functions (since 19 November 2026), 15 minutes for Web Functions, and 90 minutes for async and event-source-mapping invocations on Lambda Managed Instances. The default is 3 seconds — raise it deliberately.

Why did my function time out?

Usually one of three reasons: the timeout is still the 3-second default, the function is waiting on a network call that never returns (a VPC without a NAT gateway is the classic case), or a downstream service is slow. Check CloudWatch Logs for the invocation’s duration and errors.

Lambda vs EC2 — which should I choose?

Lambda for event-driven, short-lived, spiky work; EC2 (or containers) for long-running, continuous or stateful work. If the workload runs 24/7, a small instance is almost always cheaper.

Conclusion

Lambda’s appeal is that it removes the server from the problem: write a function, attach a trigger, and pay for milliseconds. The skill is knowing the boundaries — the 30-minute timeout, the 10,240 MB memory ceiling, the 1,000 concurrent execution limit, the cold start on a quiet API — and designing inside them. The function you built here is the whole model; everything else is triggers, permissions and composition.

From here, the useful next steps are infrastructure as code — our Terraform Tutorial for Beginners shows how to define Lambda functions in Terraform instead of clicking through the console — and the AWS Tutorial for Beginners for the services your functions will call.

Sources checked 28 Nov 2026: AWS Lambda runtimes page (Python 3.14, Node.js 24, Java 25, .NET 10; Node.js 26 and Python 3.15 in public preview); AWS Lambda limits page, crawled 28 Nov 2026 (timeout 30 minutes for Event Functions from 19 Nov 2026; 10,240 MB memory; 50 MB zipped / 250 MB unzipped; 10 GB container images; 1,000 concurrent executions); AWS Lambda pricing (free tier 1M requests + 400,000 GB-seconds; $0.20 per 1M requests; $0.0000166667 per GB-second). External references: AWS Lambda documentation · AWS Lambda pricing.

—

Scroll to Top