API keys and usage plans in AWS - Time & Space Complexity
When managing API keys and usage plans, it is important to understand how the number of API keys affects the operations needed to enforce usage limits.
We want to know how the work grows as more API keys are added to a usage plan.
Analyze the time complexity of the following operation sequence.
// Attach multiple API keys to a usage plan
for (let i = 0; i < apiKeys.length; i++) {
aws.apigateway.createUsagePlanKey({
usagePlanId: usagePlanId,
keyId: apiKeys[i].id,
keyType: 'API_KEY'
});
}
This sequence attaches each API key to a usage plan to enforce usage limits per key.
- Primary operation: createUsagePlanKey API call to attach one API key to the usage plan
- How many times: Once for each API key in the list
Each API key requires one separate call to attach it to the usage plan, so the total calls grow directly with the number of keys.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of calls increases one-to-one with the number of API keys.
Time Complexity: O(n)
This means the work grows linearly as you add more API keys to the usage plan.
[X] Wrong: "Attaching multiple API keys can be done in a single API call, so time stays the same regardless of keys."
[OK] Correct: Each API key must be attached individually, so the number of calls grows with the number of keys.
Understanding how API calls scale with input size shows you can predict system behavior and design efficient cloud solutions.
"What if the usage plan allowed attaching multiple API keys in one batch call? How would the time complexity change?"