0
0
AWScloud~5 mins

Lambda function concept in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Lambda function concept
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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
How Execution Grows With Input

Each new event causes one Lambda call, so the total calls grow directly with n.

Input Size (n)Approx. API Calls/Operations
1010 Lambda invocations
100100 Lambda invocations
10001000 Lambda invocations

Pattern observation: The number of Lambda calls grows in a straight line as n increases.

Final Time Complexity

Time Complexity: O(n)

This means if you double the number of events, the total Lambda calls double too.

Common Mistake

[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.

Interview Connect

Understanding how repeated Lambda calls add up helps you design systems that scale well and explain your reasoning clearly.

Self-Check

"What if we changed the Lambda function to process multiple events in one call? How would the time complexity change?"