0
0
AWScloud~5 mins

API keys and usage plans in AWS - Time & Space Complexity

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

Scenario Under Consideration

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.

Identify Repeating Operations
  • 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
How Execution Grows With Input

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
1010 calls
100100 calls
10001000 calls

Pattern observation: The number of calls increases one-to-one with the number of API keys.

Final Time Complexity

Time Complexity: O(n)

This means the work grows linearly as you add more API keys to the usage plan.

Common Mistake

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

Interview Connect

Understanding how API calls scale with input size shows you can predict system behavior and design efficient cloud solutions.

Self-Check

"What if the usage plan allowed attaching multiple API keys in one batch call? How would the time complexity change?"