REST API creation in AWS - Time & Space 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.
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 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.
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 |
|---|---|
| 10 | About 21 (1 API + 10 resources + 10 methods) |
| 100 | About 201 (1 API + 100 resources + 100 methods) |
| 1000 | About 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.
Time Complexity: O(n)
This means the time to create the API grows directly in proportion to the number of paths you add.
[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.
Understanding how API creation scales helps you design efficient cloud solutions and shows you can think about growth, which is valuable in real projects.
"What if we batch resource and method creation in fewer API calls? How would the time complexity change?"