AWS · Serverless

AWS Lambda

Run code in response to events without managing servers, paying only for the requests and the time your code runs.

On the SAA-C03 exam listServerlessEvent routing

What it is and what problem it solves

AWS Lambda runs your function code when something triggers it, such as an HTTP request through API Gateway, a message arriving in SQS, a file landing in S3, a schedule, or a call from another service. You upload code (or a container image), choose how much memory it gets, and Lambda allocates CPU in proportion, starts execution environments as needed, scales them with load, and shuts them down when idle.

There are no servers to patch or capacity to plan. The first request to a new environment pays a cold start (the time to start the environment and your runtime); later requests reuse the warm environment.

API Gatewaysync requestS3 / SNS / EventBridgeasync eventSQS / Kinesis / DynamoDBpoller reads a batchLambda function128 MB – 10 GB · ≤ 15 minWrites resultsDynamoDB, S3, …FailuresDLQ / on-failure destination
Lambda runs your function in response to requests, events or batches from a queue or stream

When to use it

  • Event-driven work: react to S3 uploads, queue messages, stream records, schedules and API calls.
  • Spiky or unpredictable traffic, including long periods of zero traffic.
  • Short tasks that finish within the function's time limit.
  • Glue between services, where a few lines of code transform or route data.
  • You want to pay per use and avoid running idle servers.

When to avoid it

  • Work longer than the time limit, or that needs long-lived connections: use containers on ECS or Fargate, or EC2.
  • Steady, high, predictable load where an always-on container or instance is cheaper per request.
  • Very latency-sensitive paths that cannot tolerate cold starts, unless you use provisioned concurrency or SnapStart where supported.
  • Workloads needing special hardware, large local state or a particular operating system setup beyond what a function or container image offers.

Scaling model and bottlenecks

Lambda scales by running more execution environments, each handling one request at a time. The limits are your account's concurrency quota per Region and how fast new environments are added. A burst that exceeds either is throttled. Use reserved concurrency to guarantee capacity for important functions (and to cap noisy ones), and provisioned concurrency to keep environments warm for latency-sensitive paths. Downstream systems such as databases can be overwhelmed by Lambda's scale, so cap concurrency or use RDS Proxy.

Performance, latency and throughput

More memory means more CPU, so a larger setting can finish faster and sometimes cost less overall. Cold starts depend on the runtime, package size and what runs at startup; keep initialisation light and reuse connections across invocations by creating clients outside the handler.

Limits and quotas

Several limits shape designs: a maximum run time per invocation, payload size limits for synchronous and asynchronous calls, and package size. Quotas apply per Region, and new accounts start with lower concurrency than established ones.

ItemValueContextSource
Memory 128 to 10,240 MB, in 1 MB steps
Fixed limit
Source
checked
Function timeout 900 seconds (15 minutes)
Fixed limit
Source
checked
Concurrent executions per Region 1,000
Can be raised with a quota request
The default; new accounts can start lower. Source
checked
Synchronous invocation payload 6 MB each for the request and the response
Fixed limit
Source
checked
Asynchronous invocation payload 1 MB
Fixed limit
Source
checked
Deployment package, zip 50 MB zipped; 250 MB unzipped
Fixed limit
The unzipped limit includes layers and custom runtimes. Source
checked
Container image size 10 GB, uncompressed
Fixed limit
Source
checked
Ephemeral storage (/tmp) 512 to 10,240 MB
Fixed limit
Source
checked
Scaling rate per function 1,000 execution environments every 10 seconds
Fixed limit
Source
checked

Quotas and limits change. Check the linked source before designing around a number.

Cost model

What you pay for

  • Requests: a charge per request (with a monthly free tier).
  • Duration: billed in GB-seconds, which is memory allocated multiplied by run time, rounded up to the millisecond.
  • Asynchronous events are billed as extra requests for each additional 64 KB chunk of payload beyond the first 256 KB.
  • Optional features: provisioned concurrency (billed for the time it is enabled, plus requests and duration when used), ephemeral storage above the default, SnapStart, response streaming.
  • Data transfer, and the services your function calls, bill separately.

Where it is cost-efficient

Low, bursty or unpredictable traffic, and event handlers that run briefly, where you pay for only the milliseconds used and nothing when idle.

Where costs grow

  • Constant high volume, where an always-on container or instance costs less per request.
  • Functions that wait on slow downstream calls, because waiting time is billed as duration.
  • Over-provisioned memory that adds cost without speeding up the work.
  • Provisioned concurrency left enabled on functions that do not need it.

Cost controls and common surprises

Right-size memory with measurements (the power-tuning approach), keep functions short, set timeouts so a stuck call does not run for fifteen minutes, use queues to smooth bursts, and review Lambda in Cost Explorer. Compare against a container for sustained load.

Prices differ by Region and change over time; see the pricing page linked under Sources.

Security

Controls the service provides

  • Execution role (IAM): each function has a role that defines what it may access; it gets short-lived credentials automatically.
  • Resource policy controls who or what may invoke the function.
  • Isolation: each execution environment is isolated from others.
  • Encryption of environment variables with KMS, and of the code package at rest.

What you configure

Give each function its own role with only the permissions it needs, keep secrets in Secrets Manager or Parameter Store rather than plain environment variables, validate input from event sources, patch dependencies in your package, and attach the function to a VPC only if it needs private resources (remembering that then it needs a NAT gateway or endpoints for AWS service access).

Logging and monitoring

Output goes to CloudWatch Logs automatically; CloudWatch metrics track invocations, errors, duration and throttles; X-Ray traces calls; CloudTrail records management and optionally data events.

Related security services

IAM, KMS, Secrets Manager, Parameter Store, GuardDuty Lambda protection, Inspector for code and dependency scanning.

Shared responsibility

AWS secures the runtime, the operating system and the infrastructure. You secure your code, its dependencies, its role and its configuration.

Availability, backup and failure behavior

Lambda runs across multiple Availability Zones in a Region automatically. Asynchronous invocations are retried on error and can send failures to a dead-letter queue or an on-failure destination. Stream and queue sources retry according to the source's settings. Because a request can be retried, write handlers to be idempotent. For Regional resilience, deploy the same function in a second Region and route with Route 53.

Common service combinations

API Gateway to Lambda to DynamoDB (serverless API); S3 or SQS or Kinesis as event sources; EventBridge schedules and rules; Step Functions to coordinate several functions; SNS fan-out; RDS Proxy in front of a relational database.

Business application examples

  • A function creates thumbnails whenever an image is uploaded to S3.
  • A serverless API where each route is a function behind API Gateway.
  • A worker that reads messages from an SQS queue and updates a database.

Exam cues and common confusions

  • Run code on events, no servers, pay per use: Lambda.
  • Maximum run time is 15 minutes: longer jobs go to Fargate, Batch or EC2.
  • Throttling and scaling: concurrency limits; reserved concurrency protects or caps a function; provisioned concurrency avoids cold starts.
  • Lambda in a VPC cannot reach the internet or AWS services by default; add a NAT gateway or VPC endpoints.
  • Many connections to RDS: use RDS Proxy.
  • Share code between functions: layers (or packaged libraries).
  • Failures in async invocations: a dead-letter queue or on-failure destination.

Related

Courses and lessons

Services, comparisons and patterns

Sources

Independent study material, not affiliated with or endorsed by Amazon Web Services. AWS and service names are trademarks of Amazon.com, Inc. or its affiliates.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake