AWS Lambda Explained: How Amazon’s Serverless Functions Work

AWS Lambda Explained: How Amazon's Serverless Functions Work

AWS Lambda explained simply: it is Amazon’s serverless compute service, and it runs your code in response to events without you provisioning or managing any servers. Is Lambda the right way to run your workload?

For event-driven tasks, APIs and background jobs, usually yes — you pay only for the invocations and compute time you use. For long-running or constantly busy services, containers or virtual servers may work out cheaper and simpler.

Lambda has been the reference point for serverless computing since Amazon launched it in 2014. It sits at the centre of the AWS ecosystem, connected to dozens of other services that can trigger functions or receive their output. Understanding how it works — its triggers, limits and billing — is the fastest way to judge whether serverless fits your next project.

Key takeaways

  • AWS Lambda runs code in response to events, with no servers to provision, patch or scale.
  • Functions are stateless, run for at most 15 minutes, and can use from 128 MB to 10,240 MB of memory.
  • You pay per request and per GB-second of compute, after a free tier of 1 million requests and 400,000 GB-seconds a month.
  • Cold starts, the 15-minute limit and tight coupling to AWS services are the main trade-offs.
  • Lambda fits APIs, file processing, scheduled jobs and event-driven pipelines best.

What AWS Lambda is

AWS Lambda is a compute service that runs code in response to events. You write a function — a handler plus its settings — choose a runtime such as Python, Node.js, Java, Go, Ruby or .NET, and deploy it as a ZIP archive or a container image.

Lambda then runs that code whenever a configured event arrives, and you never see the machine underneath. The service is part of the wider pattern described in our guide to cloud computing, where the provider manages the infrastructure and you manage only the code.

Each function has settings you control: the runtime, the memory size from 128 MB to 10,240 MB, the timeout up to 15 minutes, and the environment variables your code needs. CPU scales in proportion to memory, so a function with 1,769 MB of memory gets roughly the equivalent of one virtual CPU.

Ephemeral storage in the /tmp directory can be configured from 512 MB to 10,240 MB. These settings are the levers you use to balance performance against cost.

Lambda is not a general-purpose server replacement. It is a tool for short, discrete units of work that start on an event and finish quickly.

A function that processes one uploaded image, validates one webhook or transforms one database record is a natural fit. A service that must hold a connection open for hours or keep large state in memory is not.

How Lambda works: events, execution and scaling

Every Lambda invocation begins with an event. Some services push events to Lambda directly, such as API Gateway for HTTP requests, S3 for file uploads, and SNS or EventBridge for messages.

Others are polled: for SQS queues, Kinesis streams and DynamoDB Streams, Lambda runs an event source mapping that fetches batches of records and passes them to your function. Either way, your handler receives an event object, does its work, and returns a result or an error.

When an invocation starts, Lambda places your code in an execution environment — an isolated sandbox with the runtime, your code and its dependencies. If an environment is already warm from a recent invocation, your code starts almost immediately.

If not, Lambda must create one, and that setup time is the cold start. Keeping deployment packages small and choosing fast-starting runtimes keeps cold starts short.

Scaling is automatic and concurrent. Lambda can run many copies of a function at once, up to a default account limit of 1,000 concurrent executions, which you can raise by request.

Each invocation is independent, so a burst of ten thousand events spins up many parallel environments and drains just as fast. This is why Lambda handles spiky traffic so well: capacity appears exactly when it is needed and disappears when it is not.

What triggers a Lambda function

Lambda’s real power comes from its triggers, because a function is most useful when it is wired into the services around it. An HTTP request through API Gateway can invoke a function that serves an API endpoint. A file arriving in S3 can trigger a function that resizes an image or extracts text.

A message in an SQS queue can trigger a function that processes orders one batch at a time. A scheduled EventBridge rule can run a function every night to produce a report.

Database changes are another common trigger. A write to a DynamoDB table can fire a stream that invokes a function to update a search index or send a notification.

Incoming emails, IoT device messages and authentication events can all trigger functions too. The pattern is always the same: something happens in AWS, and Lambda runs code in response.

Lambda limits you need to know

Lambda’s limits shape every design decision, so it is worth knowing them before you build. The hard boundaries are generous for short tasks and absolute for long ones, and there is no way to pay your way past the per-invocation caps on a standard function.

AWS Lambda key limits at a glance
Limit Value What it means in practice
Maximum run time 15 minutes per invocation Long jobs must be split or moved elsewhere
Memory 128 MB to 10,240 MB CPU scales with memory; more memory costs more
Ephemeral storage (/tmp) 512 MB to 10,240 MB Temporary files only; nothing persists
Deployment package 50 MB zipped, 250 MB unzipped Large dependencies need layers or containers
Container image Up to 10 GB Useful for heavy dependencies
Synchronous payload 6 MB request and response Large files go through S3, not the function
Concurrent executions 1,000 by default Can be raised on request

Two of these limits cause the most redesigns. The 15-minute timeout rules out long batch jobs, video transcoding of large files, and anything that waits on a slow external process.

The 6 MB synchronous payload limit means functions should exchange large data through S3 rather than passing it directly. If your workload keeps hitting these walls, AWS Step Functions can orchestrate a chain of Lambda calls, or the work belongs on ECS or Fargate instead.

How Lambda pricing works

Lambda bills on two meters: requests and duration. Every invocation costs $0.20 per million requests, and duration is billed in GB-seconds — allocated memory multiplied by run time, rounded up to the nearest millisecond — at $0.0000166667 per GB-second on x86, or $0.0000133334 on Arm, in US East.

The free tier covers 1 million requests and 400,000 GB-seconds every month, plus 100 GiB of response streaming, and it does not expire. See also our guide to the AWS free tier for what is included and where the surprises hide.

Two details catch newcomers out. First, duration is billed for the whole time your function holds its memory, including time spent waiting on a database or an API call, so slow downstream services inflate the bill. Second, the free tier does not apply to Provisioned Concurrency, which keeps environments warm for a fixed hourly charge.

Lambda vs containers and servers

Lambda, containers and virtual servers solve different problems, and the right choice depends on the workload’s shape. Lambda wins when traffic is uneven, tasks are short, and the team wants no infrastructure to run.

Containers on ECS or Fargate win when jobs run long, need custom runtimes, or must keep running between requests. Virtual servers win when you need full control of the machine or specialised hardware.

Cost follows the same logic. A service handling a few thousand requests a day can run on Lambda for almost nothing, thanks to the free tier and scale-to-zero billing. A service handling steady traffic all day, every day, often costs less on a reserved container or server, because Lambda charges per invocation while a server’s cost is flat.

The crossover point depends on your traffic, so model both options with real numbers before choosing. Our guide to AWS pricing explains how the wider billing model works.

Abstract illustration of a single function block receiving events from several cloud services
A Lambda function sits at the centre of AWS events: requests, file uploads and queue messages all trigger the same kind of short-lived execution.

Common Lambda use cases

APIs and web backends

A function behind API Gateway can serve a mobile app backend, a webhook receiver or a small public API. Each request is one invocation, the API scales with demand, and the free tier often covers a small service outright. Best for: low-to-medium traffic APIs and webhook handlers.

File and image processing

An S3 upload can trigger a function that resizes images, extracts text from documents or validates a file format, then stores the result. Each file is processed independently, so a burst of uploads scales out automatically. Best for: media pipelines and document processing.

Scheduled jobs and automation

An EventBridge schedule can run a function nightly to generate reports, clean up old data or synchronise systems. The function runs for a few minutes and costs almost nothing the rest of the day. Best for: reports, cleanups and periodic synchronisation.

Event-driven data pipelines

Messages from SQS, Kinesis or DynamoDB Streams can trigger functions that validate, enrich and store records. The pipeline scales with the message rate, and failed records can be routed to a dead-letter queue for inspection. Best for: stream processing and record-by-record transformation.

Getting started: a practical checklist

Starting with Lambda is quick, but a few decisions made early save rework later. Work through this checklist for your first function, and revisit it before any function goes to production.

  • Pick the smallest memory that meets your latency target. More memory buys more CPU, so test 128 MB, 256 MB and 512 MB and measure both speed and cost.
  • Set a timeout close to your real need. A timeout far above reality lets a stuck function burn money; a timeout too low kills legitimate work.
  • Keep the deployment package small. Fewer dependencies mean faster cold starts and quicker deploys.
  • Make functions idempotent. Lambda retries failures, so a retried invocation must never apply the same change twice.
  • Use environment variables for configuration. Never hard-code secrets or endpoints; use Secrets Manager or Parameter Store.
  • Give the function the least privilege it needs. A narrow IAM role limits the damage if credentials leak.
  • Send logs to CloudWatch and add tracing. Structured logging and X-Ray tracing make debugging possible at scale.
  • Set a billing alarm before launch. A runaway retry loop is the classic Lambda surprise bill.

Frequently asked questions

Is AWS Lambda free?

Within limits, yes. Every account gets 1 million requests and 400,000 GB-seconds of compute free each month, plus 100 GiB of response streaming. Usage beyond that is billed per request and per GB-second.

How long can a Lambda function run?

At most 15 minutes per invocation. The default timeout is 3 seconds, and you raise it in the function settings up to the 900-second maximum.

What languages does Lambda support?

Lambda provides managed runtimes for Python, Node.js, Java, Go, Ruby, .NET and PowerShell, and you can bring your own runtime or a container image for anything else.

What is a Lambda cold start?

A cold start is the delay when Lambda must create a fresh execution environment for a function that has been idle. It ranges from tens of milliseconds to a few seconds, depending on runtime and package size.

Can Lambda run a container image?

Yes. You can deploy a function as a container image of up to 10 GB, which is useful when dependencies are too large for a ZIP package.

When should I not use Lambda?

Avoid Lambda for jobs longer than 15 minutes, workloads with constant high traffic that would be cheaper on reserved capacity, and applications that need persistent local state or long-lived connections.

Latest articles

Scroll to Top