Lambda function concept in AWS - Time & Space Complexity
We want to understand how the time to run a Lambda function changes as we increase the number of events it handles.
How does the number of events affect the total work Lambda does?
Analyze the time complexity of invoking a Lambda function multiple times.
// Pseudocode for invoking Lambda multiple times
for (int i = 0; i < n; i++) {
aws lambda invoke --function-name MyFunction --payload '{"key": "value"}' response.json
}
This sequence calls the same Lambda function n times, each with a small input.
Look at what repeats as we increase n.
- Primary operation: Lambda function invocation API call
- How many times: Exactly n times, once per loop iteration
Each new event causes one Lambda call, so the total calls grow directly with n.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 Lambda invocations |
| 100 | 100 Lambda invocations |
| 1000 | 1000 Lambda invocations |
Pattern observation: The number of Lambda calls grows in a straight line as n increases.
Time Complexity: O(n)
This means if you double the number of events, the total Lambda calls double too.
[X] Wrong: "Calling Lambda multiple times is just one operation regardless of n."
[OK] Correct: Each Lambda call is a separate operation that takes time, so more calls mean more total work.
Understanding how repeated Lambda calls add up helps you design systems that scale well and explain your reasoning clearly.
"What if we changed the Lambda function to process multiple events in one call? How would the time complexity change?"