Resources and methods in AWS - Time & Space Complexity
When working with AWS resources and methods, it's important to understand how the time to complete tasks grows as you add more resources or methods.
We want to know how the number of API calls or operations changes when we increase resources or methods.
Analyze the time complexity of creating multiple resources and attaching methods to them.
for resource_name in resource_list:
resource = api_gateway.create_resource(restApiId=api_id, parentId=parent_id, pathPart=resource_name)
api_gateway.put_method(restApiId=api_id, resourceId=resource['id'], httpMethod='GET', authorizationType='NONE')
This sequence creates a resource for each name and adds a GET method to it.
- Primary operation: Creating a resource and adding a method for each item.
- How many times: Once per resource in the list.
Each new resource requires one create call and one method call.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 20 (10 creates + 10 methods) |
| 100 | 200 (100 creates + 100 methods) |
| 1000 | 2000 (1000 creates + 1000 methods) |
Pattern observation: The number of API calls grows directly with the number of resources.
Time Complexity: O(n)
This means the time to complete grows in a straight line as you add more resources.
[X] Wrong: "Adding more methods to the same resource does not increase the number of API calls significantly."
[OK] Correct: Each method requires its own API call, so adding methods increases calls linearly with the number of methods.
Understanding how operations scale with resources helps you design efficient cloud setups and shows you can think about costs and delays realistically.
"What if we batch create resources instead of one by one? How would the time complexity change?"