Lambda integration in AWS - Time & Space Complexity
When we connect AWS Lambda to other services, it's important to know how the time to complete tasks grows as we add more work.
We want to understand how the number of Lambda calls changes when the input size changes.
Analyze the time complexity of the following operation sequence.
# For each item in a list, invoke a Lambda function
for item in items:
lambda.invoke(
FunctionName='ProcessItem',
Payload=json.dumps(item)
)
This code calls a Lambda function once for each item in a list to process them individually.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Lambda function invocation API call
- How many times: Once per item in the input list
Each new item causes one more Lambda call, so the total calls grow directly with the number of items.
| 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 increases evenly as the input size increases.
Time Complexity: O(n)
This means the total Lambda calls grow in direct proportion to the number of items to process.
[X] Wrong: "Calling Lambda once with all items is the same as calling it once per item."
[OK] Correct: Calling Lambda once per item means many separate calls, so time grows with items. One call with all items is just one call, so time does not grow the same way.
Understanding how Lambda calls scale helps you design systems that handle growing workloads smoothly and shows you can think about costs and performance clearly.
"What if we batch multiple items into a single Lambda call? How would the time complexity change?"