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?"
Practice
Solution
Step 1: Understand API key role
An API key is used to identify the client calling the API.Step 2: Identify purpose in AWS API Gateway
It helps control and track who can access the API, not data storage or encryption.Final Answer:
To identify and control who can access the API -> Option DQuick Check:
API key = identify and control access [OK]
- Confusing API keys with encryption keys
- Thinking API keys store user data
- Assuming API keys monitor server metrics
Solution
Step 1: Understand usage plan and API key relationship
Usage plans define limits and must have API keys linked to enforce them.Step 2: Correct linking process
You create a usage plan first, then add API keys to it to apply limits.Final Answer:
Create a usage plan, then add the API key to it -> Option AQuick Check:
Usage plan first, then add API key [OK]
- Trying to add usage plans to API keys
- Not linking keys and plans at all
- Assuming API keys are created inside usage plans
{"throttle": {"rateLimit": 100, "burstLimit": 200}, "quota": {"limit": 1000, "period": "DAY"}}What does this usage plan enforce?
Solution
Step 1: Interpret throttle limits
RateLimit 100 means 100 requests per second max, burstLimit 200 allows short bursts up to 200 requests.Step 2: Interpret quota limits
Quota limit 1000 per DAY means max 1000 requests allowed in one day.Final Answer:
Max 100 requests per second, burst up to 200, and 1000 requests per day -> Option CQuick Check:
Throttle = 100/sec + 200 burst, Quota = 1000/day [OK]
- Mixing burstLimit with rateLimit
- Confusing quota limit with per second limit
- Ignoring the quota period
Solution
Step 1: Check API key and usage plan link
Usage plans only apply limits if the API key is linked to them.Step 2: Verify other causes
While no limits or deployment can cause issues, the key not linked means no limits apply.Final Answer:
The API key is not associated with the usage plan -> Option BQuick Check:
Key must be linked to usage plan for limits [OK]
- Assuming usage plan limits apply without linking keys
- Ignoring deployment status
- Confusing expired keys with unlinked keys
Solution
Step 1: Define usage plan with required limits
Set quota to 5000 per month and throttle to 50 requests per second with burst 100.Step 2: Link API keys to usage plan
Adding API keys to the usage plan enables tracking and enforcement of limits per key.Final Answer:
Create usage plan with quota 5000/month and throttle 50/sec burst 100, then add API keys to the plan -> Option AQuick Check:
Usage plan sets limits + keys linked for tracking [OK]
- Trying to set limits on API keys directly
- Not linking API keys to usage plan
- Setting limits only on API Gateway stage
Ready to prove it?
Pass the test and this pattern moves unknown
