Configuring Lambda Functions and Understanding Pricing
This lesson explains the configuration settings that decide a Lambda function's performance, limits and cost.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the Lambda configuration limits.
- Calculate cost from requests and GB-seconds.
- Explain how execution environment reuse improves performance.
Configuration limits
A Lambda function's configuration sets its resources, and several limits shape what Lambda can run. Memory ranges from 128 MB to 10,240 MB, and CPU and network capacity grow in proportion, so a slow, CPU-bound function often becomes faster, and sometimes cheaper, with more memory. The timeout can be at most 15 minutes, so longer jobs need another service. /tmp storage ranges from 512 MB to 10 GB for temporary files during an invocation.
Functions run on x86_64 or on arm64 Graviton processors, which cost less for the same work. Code is deployed as a .zip package, up to 250 MB unzipped including layers, or as a container image of up to 10 GB. Environment variables, up to 4 KB in total, are encrypted at rest with KMS. The following table summarises the settings.
| Setting | Range |
|---|---|
| Memory | 128 MB to 10,240 MB (CPU and network scale with it) |
| Timeout | Up to 15 minutes |
/tmp storage | 512 MB to 10 GB |
| Architecture | x86_64 or cheaper arm64 (Graviton) |
| Package | .zip up to 50 MB zipped / 250 MB unzipped with layers, or container image up to 10 GB |
| Environment variables | 4 KB in total, encrypted with KMS |
10,240MB
Maximum memory
15min
Maximum timeout
10GB
Maximum /tmp storage
250MB
Unzipped .zip package, including layers
Lambda limits
Pricing
Lambda is charged per request plus for compute duration, measured in gigabyte-seconds, the memory configured multiplied by the time the function runs, billed per millisecond. Because CPU is allocated in proportion to memory, a function that runs much faster with more memory can cost the same or less, since its duration falls as its CPU rises.
Functions on the arm64 architecture cost less per gigabyte-second, and Compute Savings Plans apply to Lambda. Provisioned concurrency is charged for the time it is configured, whether or not it is used. Above all, there is no charge when no requests arrive, which makes Lambda the cheapest option for spiky or low-volume work.
How Lambda is priced
Execution environments
Each request runs in an execution environment that stays warm between invocations, so code outside the handler, such as database connections and SDK clients, runs once and is reused. A cold start happens when Lambda creates a new environment, adding latency for the first request.
More memory, lower cost
A CPU-bound function runs with 512 MB for 4 seconds per invocation. The team tests other memory settings:
| Memory | Duration | GB-seconds per invocation |
|---|---|---|
| 512 MB | 4.0 s | 2.0 |
| 1,024 MB | 1.9 s | 1.9 |
| 2,048 MB | 1.0 s | 2.0 |
1,024 MB is both faster and slightly cheaper than 512 MB, because CPU grows with memory. Switching to arm64 lowers the price per GB-second further. Lambda Power Tuning automates this comparison.
Which two factors determine the compute charge for a Lambda invocation?
Show answer
The memory allocated and the duration, measured in GB-seconds, plus a small charge per request.
Exam Tips
Remember for the exam
- To speed up a CPU-bound function, increase its memory.
- To reduce Lambda cost, use arm64, right-size memory and use Compute Savings Plans.
- Initialise SDK clients and connections outside the handler so they are reused.
- A workload longer than 15 minutes does not fit Lambda.