📖 Scenario: You are working as a cloud engineer for a company that wants to deploy a simple API using AWS API Gateway. The company needs to create an API, deploy it, and manage different stages like dev and prod to separate development and production environments.
🎯 Goal: Build an AWS API Gateway REST API, deploy it, and create two stages named dev and prod. This will allow the company to manage different versions of the API for testing and production.
📋 What You'll Learn
Create a REST API named SimpleAPI
Deploy the API to a deployment resource
Create two stages named dev and prod
Associate the deployment with both stages
💡 Why This Matters
🌍 Real World
Companies use API Gateway stages to separate development, testing, and production environments for their APIs. This helps manage different versions and safely deploy changes.
💼 Career
Cloud engineers and DevOps professionals often create and manage API Gateway deployments and stages to ensure reliable and organized API lifecycle management.
Progress0 / 4 steps
1
Create the REST API resource
Create a resource called SimpleAPI using AWS CloudFormation syntax with the type AWS::ApiGateway::RestApi. Set the Name property exactly to SimpleAPI.
AWS
Hint
Use AWS::ApiGateway::RestApi as the resource type and set the Name property to SimpleAPI.
2
Create the deployment resource
Add a resource called SimpleAPIDeployment of type AWS::ApiGateway::Deployment. Set the RestApiId property to reference SimpleAPI using !Ref SimpleAPI. Do not set the StageName property here.
AWS
Hint
Use AWS::ApiGateway::Deployment and reference the API with !Ref SimpleAPI.
3
Create the dev and prod stages
Add two resources: DevStage and ProdStage, both of type AWS::ApiGateway::Stage. For each stage, set StageName to dev and prod respectively. Set DeploymentId to reference SimpleAPIDeployment using !Ref SimpleAPIDeployment. Also set RestApiId to reference SimpleAPI using !Ref SimpleAPI.
AWS
Hint
Create two AWS::ApiGateway::Stage resources with StageName set to dev and prod. Reference the deployment and API with !Ref.
4
Add description to the deployment
Add a Description property to the SimpleAPIDeployment resource with the exact value Initial deployment of SimpleAPI.
AWS
Hint
Add the Description property inside the SimpleAPIDeploymentProperties section.
Practice
(1/5)
1. What is the main purpose of an API stage in AWS API Gateway?
easy
A. To monitor network traffic outside AWS
B. To store API keys for users
C. To create backend Lambda functions
D. To manage different versions or environments of the API
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 D
Quick Check:
API stages = version/environment management [OK]
Hint: Stages separate API versions or environments [OK]
Common Mistakes:
Confusing stages with API keys
Thinking stages create backend functions
Assuming stages monitor external traffic
2. Which AWS CLI command is used to create a new deployment for an API Gateway REST API?
easy
A. aws apigateway create-deployment
B. aws apigateway create-stage
C. aws apigateway deploy-api
D. aws apigateway new-deployment
Solution
Step 1: Identify the correct AWS CLI command for deployment
The command to create a deployment in API Gateway is create-deployment.
Step 2: Differentiate from other commands
create-stage creates a stage, not a deployment. Other options are invalid commands.
Final Answer:
aws apigateway create-deployment -> Option A
Quick Check:
Deployment command = create-deployment [OK]
Hint: Deploy with 'create-deployment' command [OK]
Common Mistakes:
Using create-stage instead of create-deployment
Assuming deploy-api is a valid command
Confusing deployment with stage creation
3. Given the following AWS CLI command: aws apigateway create-stage --rest-api-id abc123 --stage-name prod --deployment-id dep456 What does this command do?
medium
A. Creates a new deployment named 'prod' for API 'abc123'
B. Creates a new stage 'prod' linked to deployment 'dep456' for API 'abc123'
C. Deletes the stage 'prod' from API 'abc123'
D. Updates the deployment 'dep456' with stage 'prod'
Solution
Step 1: Analyze the command parameters
The command is create-stage with 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 B
Quick Check:
create-stage + deployment-id = new stage linked to deployment [OK]
Hint: create-stage links stage to deployment by deployment-id [OK]
Common Mistakes:
Confusing stage creation with deployment creation
Thinking it deletes or updates instead
Mixing up stage name and deployment ID
4. You ran this command to deploy your API stage: aws apigateway create-stage --rest-api-id abc123 --stage-name test --deployment-id dep789 But you get an error saying the deployment ID does not exist. What is the likely cause?
medium
A. The deployment ID 'dep789' was not created before creating the stage
B. The stage name 'test' is invalid
C. The rest-api-id 'abc123' is incorrect format
D. You must create the stage before creating the deployment
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 A
Quick Check:
Stage needs existing deployment ID [OK]
Hint: Create deployment before stage with deployment ID [OK]
Common Mistakes:
Assuming stage name format causes error
Thinking API ID format is the issue
Believing stage must be created before deployment
5. You want to deploy a new version of your API to a 'prod' stage without affecting the current live API. Which sequence of AWS CLI commands should you use?
hard
A. aws apigateway create-deployment -> aws apigateway create-stage with 'prod'
B. aws apigateway create-stage with 'prod' -> aws apigateway create-deployment
C. aws apigateway create-deployment -> aws apigateway update-stage with 'prod'
D. aws apigateway update-stage with 'prod' -> aws apigateway create-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
Use update-stage to 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 C
Quick Check:
Deploy then update stage to switch versions [OK]
Hint: Create deployment then update existing stage [OK]
Common Mistakes:
Creating a new stage instead of updating existing
Updating stage before deployment exists
Assuming create-stage can update existing stage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.