Bird
Raised Fist0
AWScloud~5 mins

Lambda pricing model in AWS - Commands & Configuration

Choose your learning style10 modes available
Introduction
AWS Lambda pricing is based on how many times your code runs and how long it takes to run. You pay only for the compute time you use, measured in milliseconds, and the number of requests.
When you want to run code without managing servers and pay only for the actual usage.
When you have unpredictable workloads that can scale automatically without upfront costs.
When you want to build event-driven applications that respond to changes or triggers.
When you want to run small pieces of code quickly without worrying about infrastructure.
When you want to optimize costs by paying only for the compute time your code consumes.
Commands
This command shows your current Lambda usage and limits, helping you understand your free tier and usage.
Terminal
aws lambda get-account-settings
Expected OutputExpected
{ "AccountLimit": { "TotalCodeSize": 80530636800, "CodeSizeUnzipped": 262144000, "CodeSizeZipped": 52428800, "ConcurrentExecutions": 1000, "UnreservedConcurrentExecutions": 1000 }, "AccountUsage": { "TotalCodeSize": 12345678, "FunctionCount": 5 } }
This command runs your Lambda function once, which counts as one request and uses compute time based on how long it runs.
Terminal
aws lambda invoke --function-name example-function output.txt
Expected OutputExpected
{ "StatusCode": 200, "ExecutedVersion": "$LATEST" }
→
--function-name - Specifies which Lambda function to run
This command retrieves the average execution duration of your Lambda function, which affects your cost because you pay for compute time.
Terminal
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration --dimensions Name=FunctionName,Value=example-function --start-time 2024-06-01T00:00:00Z --end-time 2024-06-01T01:00:00Z --period 60 --statistics Average
Expected OutputExpected
{ "Label": "Duration", "Datapoints": [ { "Timestamp": "2024-06-01T00:00:00Z", "Average": 150.0, "Unit": "Milliseconds" } ] }
→
--metric-name - Specifies the metric to check, here the execution duration
→
--dimensions - Filters metrics for the specific Lambda function
Key Concept

If you remember nothing else, remember: AWS Lambda pricing depends on how many times your function runs and how long each run takes.

Common Mistakes
Ignoring the function's memory size when estimating cost
Lambda pricing also depends on the memory allocated, which affects the compute cost per millisecond.
Always consider the memory size setting because higher memory increases the price per millisecond.
Assuming Lambda is free after the free tier
The free tier covers 1 million requests and 400,000 GB-seconds per month; usage beyond that is charged.
Monitor your usage and understand the free tier limits to avoid unexpected charges.
Summary
Use 'aws lambda get-account-settings' to check your Lambda usage and limits.
Invoke your Lambda function to generate requests and compute time usage.
Check execution duration with CloudWatch metrics to understand compute time costs.

Practice

(1/5)
1. What two main factors determine the cost of an AWS Lambda function?
easy
A. Number of requests and compute time
B. Storage size and network bandwidth
C. Number of users and API calls
D. Memory size and database queries

Solution

  1. Step 1: Understand AWS Lambda pricing basics

    AWS Lambda charges based on how many times your function runs (requests) and how long it runs (compute time).
  2. Step 2: Identify the pricing factors

    Memory size affects compute time cost but the main factors are requests and compute time.
  3. Final Answer:

    Number of requests and compute time -> Option A
  4. Quick Check:

    Requests + compute time = cost [OK]
Hint: Remember: pay for calls and duration only [OK]
Common Mistakes:
  • Confusing storage or bandwidth as pricing factors
  • Thinking memory size alone determines cost
  • Mixing API calls with requests
2. Which of the following is the correct way to express AWS Lambda pricing units?
easy
A. Memory in MB and network packets
B. Requests per hour and CPU cycles
C. Number of requests and GB-seconds
D. Storage in GB and function calls

Solution

  1. Step 1: Recall AWS Lambda pricing units

    Lambda pricing is based on number of requests and compute time measured in GB-seconds (memory size x execution time).
  2. Step 2: Match correct units

    Requests count how many times function runs; GB-seconds measure memory used over time.
  3. Final Answer:

    Number of requests and GB-seconds -> Option C
  4. Quick Check:

    Requests + GB-seconds = pricing units [OK]
Hint: Think requests and memory-time units [OK]
Common Mistakes:
  • Using CPU cycles or network packets incorrectly
  • Confusing storage with compute time
  • Mixing units like MB with packets
3. If a Lambda function runs 1,000,000 times with 512 MB memory for 1 second each, which factor mainly increases the cost?
medium
A. Execution time of 1 second per request
B. Network bandwidth used by the function
C. Memory size doubling from 256 MB to 512 MB
D. Number of requests being 1,000,000

Solution

  1. Step 1: Understand cost components

    Cost depends on requests and GB-seconds (memory size x execution time x requests).
  2. Step 2: Analyze impact of memory size

    Doubling memory from 256 MB to 512 MB doubles GB-seconds, increasing cost significantly, but the number of requests (1,000,000) is the main driver of total cost.
  3. Final Answer:

    Number of requests being 1,000,000 -> Option D
  4. Quick Check:

    Requests x GB-seconds = total cost [OK]
Hint: Number of requests greatly impacts total cost [OK]
Common Mistakes:
  • Ignoring number of requests effect
  • Thinking network bandwidth affects Lambda cost
  • Assuming execution time or memory alone drives cost
4. A developer notices their Lambda cost is higher than expected. They set memory to 1024 MB but function runs only 100 ms. What is the likely issue?
medium
A. Memory size is too high for short execution time
B. Number of requests is too low
C. Function execution time is too long
D. Free tier is not applied to this function

Solution

  1. Step 1: Review memory and execution time relation

    Cost depends on memory size multiplied by execution time. High memory with short time still costs more than lower memory.
  2. Step 2: Identify cost cause

    Setting memory to 1024 MB increases GB-seconds cost even if function runs only 100 ms.
  3. Final Answer:

    Memory size is too high for short execution time -> Option A
  4. Quick Check:

    High memory + short time can increase cost [OK]
Hint: High memory with short run still costs more [OK]
Common Mistakes:
  • Assuming short execution time always means low cost
  • Ignoring memory size impact
  • Thinking free tier always applies
5. A company uses Lambda functions with 256 MB memory running 200 ms per request. They want to reduce cost without changing code. Which approach helps most?
hard
A. Switch to EC2 instances for better pricing
B. Reduce memory size to 128 MB if function still runs correctly
C. Increase number of requests to use free tier fully
D. Increase memory size to reduce execution time

Solution

  1. Step 1: Understand cost relation to memory and time

    Cost = requests x memory size x execution time. Reducing memory lowers GB-seconds cost if function still works.
  2. Step 2: Evaluate options

    Reducing memory to 128 MB saves cost if performance is acceptable. Increasing memory or requests raises cost. Switching to EC2 is a different model and may not be cheaper.
  3. Final Answer:

    Reduce memory size to 128 MB if function still runs correctly -> Option B
  4. Quick Check:

    Lower memory reduces GB-seconds cost [OK]
Hint: Lower memory if function still works to save cost [OK]
Common Mistakes:
  • Increasing memory without checking cost impact
  • Thinking more requests reduce cost
  • Assuming EC2 always cheaper than Lambda
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard