API deployment and stages in AWS - Time & Space Complexity
When deploying an API in AWS, we want to know how the time to deploy changes as we add more stages or APIs.
We ask: How does deployment time grow when we increase the number of stages or APIs?
Analyze the time complexity of the following operation sequence.
# Create a new API
aws apigateway create-rest-api --name "MyAPI"
# For each stage, deploy the API
for stage in ["dev", "test", "prod"]:
aws apigateway create-deployment --rest-api-id <api-id> --stage-name $stage
# Update stage settings if needed
aws apigateway update-stage --rest-api-id <api-id> --stage-name "prod" --patch-operations ...
This sequence creates an API, deploys it to multiple stages, and updates stage settings.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: The
create-deploymentcall for each stage. - How many times: Once per stage (e.g., 3 times for dev, test, prod).
Each new stage requires a separate deployment call, so the total calls grow as the number of stages grows.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 stages | 10 deployment calls |
| 100 stages | 100 deployment calls |
| 1000 stages | 1000 deployment calls |
Pattern observation: Deployment calls increase directly with the number of stages.
Time Complexity: O(n)
This means deployment time grows in a straight line as you add more stages.
[X] Wrong: "Deploying multiple stages happens all at once, so time stays the same."
[OK] Correct: Each stage requires its own deployment call, so time adds up with each stage.
Understanding how deployment time scales helps you plan and explain API rollout strategies clearly and confidently.
"What if we deploy multiple APIs instead of stages? How would the time complexity change?"
Practice
Solution
Step 1: Understand API stages concept
API stages in AWS API Gateway represent different versions or environments like development, testing, or production.Step 2: Identify the role of stages
Stages allow you to deploy and manage separate API versions independently.Final Answer:
To manage different versions or environments of the API -> Option DQuick Check:
API stages = version/environment management [OK]
- Confusing stages with API keys
- Thinking stages create backend functions
- Assuming stages monitor external traffic
Solution
Step 1: Identify the correct AWS CLI command for deployment
The command to create a deployment in API Gateway iscreate-deployment.Step 2: Differentiate from other commands
create-stagecreates a stage, not a deployment. Other options are invalid commands.Final Answer:
aws apigateway create-deployment -> Option AQuick Check:
Deployment command = create-deployment [OK]
- Using create-stage instead of create-deployment
- Assuming deploy-api is a valid command
- Confusing deployment with stage creation
aws apigateway create-stage --rest-api-id abc123 --stage-name prod --deployment-id dep456What does this command do?
Solution
Step 1: Analyze the command parameters
The command iscreate-stagewith parameters for API ID, stage name, and deployment ID.Step 2: Understand the effect of create-stage
This creates a new stage named 'prod' that points to the deployment 'dep456' for the API 'abc123'.Final Answer:
Creates a new stage 'prod' linked to deployment 'dep456' for API 'abc123' -> Option BQuick Check:
create-stage + deployment-id = new stage linked to deployment [OK]
- Confusing stage creation with deployment creation
- Thinking it deletes or updates instead
- Mixing up stage name and deployment ID
aws apigateway create-stage --rest-api-id abc123 --stage-name test --deployment-id dep789But you get an error saying the deployment ID does not exist. What is the likely cause?
Solution
Step 1: Understand the dependency between deployment and stage
A stage must point to an existing deployment. If deployment ID does not exist, stage creation fails.Step 2: Identify the error cause
The error indicates deployment 'dep789' was not created or is invalid before stage creation.Final Answer:
The deployment ID 'dep789' was not created before creating the stage -> Option AQuick Check:
Stage needs existing deployment ID [OK]
- Assuming stage name format causes error
- Thinking API ID format is the issue
- Believing stage must be created before deployment
Solution
Step 1: Deploy new API version
First, create a new deployment to capture the latest API changes.Step 2: Update existing 'prod' stage to point to new deployment
Useupdate-stageto switch the 'prod' stage to the new deployment without creating a new stage.Final Answer:
aws apigateway create-deployment -> aws apigateway update-stage with 'prod' -> Option CQuick Check:
Deploy then update stage to switch versions [OK]
- Creating a new stage instead of updating existing
- Updating stage before deployment exists
- Assuming create-stage can update existing stage
Ready to prove it?
Pass the test and this pattern moves unknown
