Key pairs for SSH access in AWS - Time & Space Complexity
When creating key pairs for SSH access in AWS, it is important to understand how the time to create and manage these keys grows as you add more keys.
We want to know how the number of operations changes when we create many key pairs.
Analyze the time complexity of the following operation sequence.
// Create multiple key pairs for SSH access
for (let i = 0; i < n; i++) {
aws ec2 create-key-pair --key-name "my-key-" + i
}
This sequence creates n separate SSH key pairs in AWS, each with a unique name.
- Primary operation: The
create-key-pairAPI call to AWS EC2. - How many times: This call is made once for each key pair, so n times.
Each new key pair requires one API call, so the total number of calls grows directly with the number of keys.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls increases one-for-one with the number of key pairs created.
Time Complexity: O(n)
This means the time to create key pairs grows linearly as you add more keys.
[X] Wrong: "Creating multiple key pairs can be done with a single API call, so time stays the same no matter how many keys."
[OK] Correct: Each key pair requires its own API call; AWS does not support batch creation of key pairs in one request.
Understanding how operations scale with input size helps you design efficient cloud workflows and shows you can think about resource management clearly.
"What if AWS allowed batch creation of key pairs in one API call? How would the time complexity change?"