What Is AWS Lambda? The Serverless Secret Nobody Explains

A developer works on serverless code with the AWS Lambda console open on a laptop.

What Is AWS Lambda? The Serverless Secret Nobody Explains

A developer works on serverless code with the AWS Lambda console open on a laptop.

Ask what is aws lambda and how does it work, and most answers say the same thing: it runs code without servers. That is true, and it is also unhelpful, because it does not explain what actually happens when your code runs, what it costs, or when Lambda is the wrong tool entirely.

The simple version is this. You write a small piece of code, called a function, and upload it to AWS.

When something happens, a file lands in a storage bucket, a user hits an API, a message arrives in a queue, Lambda runs your function, and then it stops. You pay only for the time it ran.

This guide explains Lambda in plain language: functions, events and triggers, the execution lifecycle, IAM roles, cold starts, pricing, and the fifteen-minute limit that catches beginners by surprise.

The direct answer is that AWS Lambda is a serverless compute service that runs your code in response to events, without you provisioning, patching or managing any server. You provide the code, configure its memory and timeout, and define what triggers it, and AWS handles the infrastructure.

Lambda is event-driven and stateless. Each invocation runs in an isolated execution environment, scales automatically to handle many events at once, and you are billed in milliseconds of execution time plus the number of requests, with no charge when nothing is running.

Key Takeaways

  • AWS Lambda runs your code in response to events, with no servers to provision, patch or manage.
  • A Lambda function is a small, single-purpose piece of code with a handler, a runtime and a configuration.
  • Triggers connect events, such as file uploads or API requests, to the functions that handle them.
  • An IAM execution role defines exactly what a function is allowed to do in your AWS account.
  • Lambda functions can run for at most fifteen minutes, so long-running jobs belong elsewhere.

A monitor shows the AWS Lambda console with event sources triggering a function.
What Is Serverless, and Where Does Lambda Fit?

Serverless does not mean there are no servers. It means you do not manage them. AWS owns the servers, patches them, scales them and keeps them running, while you only think about your code. The servers still exist, they are just someone else’s problem now.

Lambda is the compute piece of serverless on AWS. A complete serverless application usually combines Lambda for code, API Gateway for HTTP routing, DynamoDB for data, and S3 for storage, all managed, all scaling automatically. Lambda is the engine, and serverless is the architecture pattern around it.

The difference from a traditional server is the billing model. A rented server bills for being on, whether or not it does useful work. Lambda bills only for the milliseconds your code actually runs, plus a small charge per request, which is why it suits workloads that run in bursts.

That model changes how you design software. Instead of one large application running all the time, you build many small functions that each do one job and run only when needed. It is a different way of thinking, and it takes some getting used to.

How Does AWS Lambda Work, Step by Step?

Everything starts with an event. An event is a piece of information about something that happened: a customer uploaded a photo, an order was placed, a scheduled time arrived, or a message landed in a queue. The event carries the data your function needs to do its job.

A trigger connects that event to your function. Common triggers include an HTTP request through API Gateway, a file upload to S3, a new record in a DynamoDB table, a message in an SQS queue, or a schedule from EventBridge. When the event happens, the trigger invokes the function.

Lambda then prepares an execution environment, a lightweight, isolated space containing your code and its runtime. The runtime passes the event to your function’s handler, which is the entry point method AWS calls. Your code runs, does its work, and returns a result if one is needed.

When the function finishes, the environment may be kept warm for a short time in case another event arrives, or it may be shut down. Either way, you stop paying the moment execution ends, because billing is measured in milliseconds of actual run time.

The Execution Lifecycle: Init, Invoke, Shutdown

Every Lambda execution has three phases. During initialisation, Lambda prepares the runtime and loads your function code. During invocation, it runs your handler with the event data. During shutdown, the environment is removed when it is no longer needed.

The important detail is reuse. Lambda can reuse an existing execution environment for the next invocation, which skips the initialisation phase and makes the function faster. Code that runs during initialisation, such as opening a database connection, may run only once across many invocations.

Rows of server racks with blinking lights fill a data centre corridor.
Functions, Runtimes and Handlers Explained

A Lambda function is the fundamental unit of execution. It is a self-contained block of code that performs one specific task and then stops. Good Lambda functions are small and focused: resize an image, send a confirmation email, or validate an order, rather than doing everything at once.

The runtime is the language environment your code runs in. Lambda supports Python, Node.js, Java, Go, Ruby and .NET natively, and you can bring your own runtime with a container image. Choose the language your team already knows, because the runtime rarely decides whether Lambda fits.

The handler is the entry point AWS invokes when your function runs. It receives the event and a context object, runs your logic, and returns a result when appropriate. Everything your function needs to know arrives through the event, which keeps functions stateless and easy to test.

Configuration sets the limits: memory from 128 MB to 10,240 MB, timeout from one second to fifteen minutes, and the IAM execution role. Memory also controls CPU power, because AWS allocates CPU in proportion to the memory you choose, so more memory means a faster function as well as a bigger one.

IAM Execution Roles in Plain Language

A Lambda function needs permission to interact with other AWS services, and it gets that permission through an IAM execution role. The role is a set of rules that says what the function is allowed to do: read from this bucket, write to that table, send a message to this queue.

Think of the role as the function’s identity badge. When your code tries to read a file from S3, AWS checks the badge first. If the role allows it, the read succeeds. If not, the function gets an access denied error, and nothing else happens.

The rule to follow is least privilege: give each function only the permissions it actually needs, and nothing more. A function that resizes images needs read access to one bucket and write access to another, not access to your whole account.

This is also a security boundary. If a function is ever compromised, the damage is limited to what its role allows. A tightly scoped role turns a bad day into a small incident instead of a catastrophe.

Hands type a Python Lambda function in a code editor on a laptop screen.
Cold Starts, Pricing and the Fifteen-Minute Limit

A cold start happens when Lambda must create a new execution environment before running your function, usually because no warm environment is available. The delay is normally a fraction of a second, but it can be longer for large functions or uncommon runtimes, and it matters most for user-facing APIs.

Warm environments avoid the delay, because the runtime is already loaded. Keeping functions warm happens naturally under steady traffic, and provisioned concurrency can guarantee warm environments for latency-sensitive APIs, at an extra cost.

Pricing has two dimensions: the number of requests, and the compute time in gigabyte-seconds. The free tier includes one million requests and 400,000 gigabyte-seconds of compute per month, which covers a surprising number of side projects and small production workloads entirely for free.

The fifteen-minute limit is the hard boundary. No Lambda function can run longer than fifteen minutes, and that rules out long batch jobs, large video processing, and anything that runs for hours. Those workloads belong on EC2, Fargate, or a batch service instead.

AWS Lambda vs EC2 vs Fargate Compared

FactorLambdaEC2Fargate
Server managementNone, AWS manages itYou manage the serverAWS manages the host
BillingPer millisecond of executionPer hour the server runsPer second of container run
ScalingAutomatic per eventManual or Auto ScalingAutomatic per task
Max runtime15 minutesUnlimitedUnlimited
Best forEvent-driven, short tasksLong-running, custom setupsContainers without servers
Cold startsYes, possible delayNoContainer startup time

Lambda First-Project Checklist

Use this checklist for your first Lambda function, so the common beginner mistakes are caught before they cost you time or money.

  1. Pick a small, single-purpose job that finishes in seconds, not a long batch task.
  2. Choose a runtime your team already knows, such as Python or Node.js.
  3. Define the trigger first, and make sure the event carries the data the function needs.
  4. Create an IAM execution role with least privilege, only the permissions the function needs.
  5. Set the timeout and memory deliberately, and remember memory also controls CPU power.
  6. Test with a real event, not just a hello-world payload, before you wire it to production.
  7. Set a billing alert so a runaway function cannot surprise you at the end of the month.

Frequently Asked Questions

What is AWS Lambda in simple terms?

AWS Lambda is a service that runs your code when something happens, without you managing any server. You write a function, tell AWS what should trigger it, and Lambda runs it, scales it automatically, and charges you only for the milliseconds it executes.

What triggers a Lambda function?

Common triggers include an HTTP request through API Gateway, a file upload to S3, a new record in DynamoDB, a message in an SQS queue, or a scheduled time from EventBridge. The trigger connects an event to the function that should handle it.

What is a cold start in AWS Lambda?

A cold start is the delay when Lambda must create a new execution environment before running your function, because no warm environment is available. It is usually a fraction of a second, but it can be longer for large functions, and it matters most for user-facing APIs.

How much does AWS Lambda cost?

You pay for the number of requests and the compute time in gigabyte-seconds, measured in milliseconds. The free tier includes one million requests and 400,000 gigabyte-seconds per month, which covers many small projects entirely for free.

What is the maximum runtime for a Lambda function?

Fifteen minutes. No Lambda function can run longer than that, which is why long batch jobs, large video processing and anything that runs for hours belongs on EC2, Fargate, or a batch service instead of Lambda.

When should you not use AWS Lambda?

Avoid Lambda for long-running jobs, workloads that need a persistent connection, CPU-heavy tasks that run for hours, and anything with highly predictable steady traffic where a reserved server is cheaper.

Conclusion

AWS Lambda is simple at its core: write a small function, connect it to an event, and let AWS run it. No servers to patch, no scaling to configure, and no bill when nothing is running. That simplicity is why it powers so much of the modern web.

The skill is knowing its limits. Keep functions small, give them least-privilege roles, watch for cold starts on user-facing APIs, and respect the fifteen-minute boundary. Do that, and Lambda will quietly handle work that used to need a server running around the clock.

For more on this topic, see our guides to AWS Lambda production mistakes to avoid, what AWS Lambda actually costs, AWS vs Azure vs Google Cloud and AWS Fargate vs Lambda.

on this page