0
0
AWScloud~5 mins

REST API creation in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: REST API creation
O(n)
Understanding Time Complexity

When creating a REST API on AWS, it's important to understand how the time to set up and respond grows as you add more resources or requests.

We want to know how the number of API calls or operations changes as the API grows.

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// Create REST API
aws apigateway create-rest-api --name MyApi

// Create resource for each path
aws apigateway create-resource --rest-api-id apiId --parent-id rootId --path-part resourceName

// Create method for each resource
aws apigateway put-method --rest-api-id apiId --resource-id resourceId --http-method GET --authorization-type NONE

// Deploy API
aws apigateway create-deployment --rest-api-id apiId --stage-name prod
    

This sequence creates a REST API, adds resources and methods for each path, and deploys it.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Creating resources and methods for each API path.
  • How many times: Once for the API, then once per resource path added.
How Execution Grows With Input

Each new API path requires creating a resource and a method, so the number of operations grows as you add more paths.

Input Size (n)Approx. Api Calls/Operations
10About 21 (1 API + 10 resources + 10 methods)
100About 201 (1 API + 100 resources + 100 methods)
1000About 2001 (1 API + 1000 resources + 1000 methods)

Pattern observation: The number of operations grows roughly in a straight line as you add more API paths.

Final Time Complexity

Time Complexity: O(n)

This means the time to create the API grows directly in proportion to the number of paths you add.

Common Mistake

[X] Wrong: "Creating the API once means adding many paths is still fast and constant time."

[OK] Correct: Each path requires separate resource and method creation, so the total work grows with the number of paths.

Interview Connect

Understanding how API creation scales helps you design efficient cloud solutions and shows you can think about growth, which is valuable in real projects.

Self-Check

"What if we batch resource and method creation in fewer API calls? How would the time complexity change?"