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?"
Practice
Solution
Step 1: Understand Lambda integration role
Lambda integration allows API Gateway to trigger Lambda functions when an API request is made.Step 2: Compare options with this role
Only To connect API Gateway to Lambda functions so they run code on requests describes connecting API Gateway to Lambda to run code on requests.Final Answer:
To connect API Gateway to Lambda functions so they run code on requests -> Option CQuick Check:
Lambda integration = connect API Gateway to Lambda [OK]
- Confusing Lambda integration with data storage
- Thinking it creates virtual machines
- Mixing it with monitoring services
Solution
Step 1: Identify Lambda integration syntax
Lambda integration uses type AWS_PROXY and the Lambda function ARN as URI.Step 2: Match options with correct syntax
--integration-type AWS_PROXY --integration-uri arn:aws:lambda:region:account-id:function:function-name correctly uses AWS_PROXY and Lambda ARN format.Final Answer:
--integration-type AWS_PROXY --integration-uri arn:aws:lambda:region:account-id:function:function-name -> Option BQuick Check:
AWS_PROXY + Lambda ARN = correct syntax [OK]
- Using HTTP or MOCK integration types for Lambda
- Incorrect ARN format for Lambda function
- Confusing AWS integration with EC2 ARN
{
"Resources": {
"MyFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"Runtime": "nodejs18.x",
"Events": {
"ApiEvent": {
"Type": "Api",
"Properties": {
"Path": "/hello",
"Method": "get"
}
}
}
}
}
}
}Solution
Step 1: Analyze the SAM template event
The event defines an API trigger on path /hello with GET method linked to the Lambda function.Step 2: Understand behavior on API call
Calling GET /hello triggers the Lambda function as defined.Final Answer:
API Gateway triggers the Lambda function on GET /hello requests -> Option AQuick Check:
API event with GET triggers Lambda [OK]
- Assuming static response without Lambda call
- Confusing HTTP methods for trigger
- Thinking deployment fails without explicit integration
Solution
Step 1: Understand 403 Forbidden meaning
403 means access denied, often due to missing permissions.Step 2: Check Lambda invoke permissions
API Gateway must have permission to invoke Lambda; missing this causes 403 errors.Final Answer:
API Gateway lacks permission to invoke the Lambda function -> Option AQuick Check:
403 Forbidden = missing invoke permission [OK]
- Blaming Lambda code errors for 403
- Assuming wrong URL causes 403
- Thinking timeout causes 403 instead of 504
Solution
Step 1: Identify integration type for full request forwarding
AWS_PROXY integration forwards the entire client request to Lambda and returns Lambda's response directly.Step 2: Confirm permissions and setup
Granting API Gateway permission to invoke Lambda is required for this integration to work.Final Answer:
Use AWS_PROXY integration type with Lambda and grant invoke permissions -> Option DQuick Check:
AWS_PROXY + invoke permission = full request forwarding [OK]
- Using MOCK for dynamic Lambda calls
- Using HTTP integration which doesn't call Lambda directly
- Using AWS integration without proxy causing manual mapping
Ready to prove it?
Pass the test and this pattern moves unknown
