0
0
AWScloud~5 mins

Resources and methods in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Resources and methods
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations
  • Primary operation: Creating a resource and adding a method for each item.
  • How many times: Once per resource in the list.
How Execution Grows With Input

Each new resource requires one create call and one method call.

Input Size (n)Approx. Api Calls/Operations
1020 (10 creates + 10 methods)
100200 (100 creates + 100 methods)
10002000 (1000 creates + 1000 methods)

Pattern observation: The number of API calls grows directly with the number of resources.

Final Time Complexity

Time Complexity: O(n)

This means the time to complete grows in a straight line as you add more resources.

Common Mistake

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

Interview Connect

Understanding how operations scale with resources helps you design efficient cloud setups and shows you can think about costs and delays realistically.

Self-Check

"What if we batch create resources instead of one by one? How would the time complexity change?"