Amazon API Gateway allows you to deploy, host and manage APIs. The service runs within stages that exist in the lifecycle of an API. Each stage of an API represents a specific state of the API, reflected by the API’s deployment status at different stages in the lifecycle. These stages are typically named along the lines of ‘dev’, ‘prod’, ‘beta’, etc.
Each stage is a named reference to a deployment of an API which includes the setup for caching, throttling, logging, and other configurations. It holds important configuration information, and developers can make changes to the API in one stage without affecting another. This is especially advantageous when the same API is being used in different applications or different environments.
In API Gateway, each stage is associated with a different base URL, the structure of which is as follows:
https://
For instance, if you had an API with a “test” and “prod” stage, they may have URLs like these:
https://xxxxxx.execute-api.us-east1.amazonaws.com/test
https://xxxxxx.execute-api.us-east1.amazonaws.com/prod
Here, each URL would lead to a different version of your API.
Custom Domains
Even though API Gateway assigns a default URL to each stage, you may want to use your own domain name to better represent your service or company. This is where custom domains come into play.
API Gateway allows you to use a custom domain to route requests to your API stages. In AWS, you can configure a custom domain in API Gateway, and map it to a specific stage of your API.
For instance, if you have a custom domain “api.example.com”, you may wish to map “api.example.com/beta” to the “dev” stage of your API, and “api.example.com/live” to the “prod” stage.
The URLs will then look more professional and user-friendly:
https://api.example.com/beta (instead of https://xxxxxx.execute-api.us-east1.amazonaws.com/test)
https://api.example.com/live (instead of https://xxxxxx.execute-api.us-east1.amazonaws.com/prod)
Creating and managing a custom domain in API Gateway involves the following steps:
- Register a domain name. You can use Route 53 or any other domain name registrar. If using Route 53, you can easily create an SSL/TLS certificate using AWS Certificate Manager (ACM).
- Create a custom domain name in API Gateway, specifying your ACM certificate.
- Configure the mapping from paths under your custom domain name (e.g., /beta, /live) to your API stages (e.g., dev, prod)
- Point your domain name to the API Gateway service by creating a DNS record in Route 53. If using another domain name registrar, you need to create a CNAME record that points to the API Gateway.
In summary, API Gateway stages and custom domains are ideally used together in AWS to provide a professional, user-friendly interface for managing and interacting with APIs. Both are key aspects to understand for the DVA-C02 exam to become an AWS Certified Developer – Associate.
Practice Test
True/False: API Gateway stages are snapshots of the configuration and are treated as separate environments.
- True
- False
Answer: True
Explanation: API Gateway stages represent different environments like DEV, TEST, or PROD. They are snapshots of the configuration of an API Gateway.
Which of the following are important attributes of an API Gateway stage? (Multiple Select)
- A) Stage name
- B) Deployment ID
- C) Stage description
- D) All of the above
Answer: D) All of the above
Explanation: All of these are important attributes of an API Gateway stage. The stage name is the identifier of the stage, the deployment ID is the identifier of the deployment, and the stage description gives detailed information about the stage.
True/False: You can route traffic to specific versions of your API through API Gateway stages.
- True
- False
Answer: True
Explanation: This is a key feature of API Gateway stages. You can route traffic to specific versions of your API depending on the stage.
True/False: You cannot attach a custom domain name to an API Gateway.
- True
- False
Answer: False
Explanation: API Gateway supports custom domain names. You can route traffic from your domain to your APIs using custom domain names in API Gateway.
API Gateway custom domain names cannot support which type of certificate issued by AWS Certificate Manager?
- A) Regional
- B) Edge optimized
- C) Regional and Edge optimized
- D) None of the above
Answer: D) None of the above
Explanation: API Gateway custom domain names can support either a Regional or an Edge optimized certificate issued by the AWS Certificate Manager.
What is the correct term for the path after the endpoint of a custom domain name in API Gateway?
- A) Base path
- B) Endpoint path
- C) Root path
- D) Resource path
Answer: A) Base path
Explanation: The path after the endpoint in a custom domain name is known as the base path.
True/False: API Gateway stages are always CORS enabled.
- True
- False
Answer: False
Explanation: CORS is not automatically enabled in API gateway stages. It has to be manually configured based on the requirements.
Which of the following are key features of API Gateway stages? (Multiple Select)
- A) Version management
- B) Traffic management
- C) Monitoring
- D) All of the above
Answer: D) All of the above
Explanation: API Gateway stages support version management, traffic management and it also provides monitoring tools like CloudWatch.
In API Gateway, a stage variable is a(n) _____.
- A) Immutable variable
- B) Name-value pair linked to a stage
- C) Configuration Snapshot
- D) None of the above
Answer: B) Name-value pair linked to a stage
Explanation: Stage variables are name-value pairs associated with a stage, enabling you to dynamically adjust the behavior of your APIs according to the stage.
True/False: A custom domain name in API Gateway can be associated with multiple base path mappings.
- True
- False
Answer: True
Explanation: A custom domain name is not restricted to just one base path mapping. It can be associated with multiple base path mappings.
True/False: Custom domain names can only be associated with REST APIs, not HTTP APIs in API Gateway.
- True
- False
Answer: False
Explanation: Custom domain names in API Gateway can be associated with both REST APIs and HTTP APIs.
True/False: Stage descriptions in API Gateway can be updated after initial setup.
- True
- False
Answer: True
Explanation: The stage description is mutable. It means you can update it after the initial setup.
True/False: Deployment IDs are unique for each API Gateway stage.
- True
- False
Answer: True
Explanation: Each deployment ID is unique to a stage as it represents a snapshot of the API’s configuration at a given point in time.
What is not included in the API Gateway stage setting?
- A) Access logs
- B) Default method throttling
- C) Client certificate
- D) Base path mapping
Answer: D) Base path mapping
Explanation: Base path mapping is not part of a stage setting; rather, it is associated with a custom domain name in API Gateway.
True/False: You cannot use both regional and edge-optimized custom domain names at the same time in API Gateway.
- True
- False
Answer: False
Explanation: These two types of custom domain names are not mutually exclusive. You can use both regional and edge-optimized custom domain names at the same time in API Gateway.
Interview Questions
What is an API Gateway stage in AWS?
An API Gateway stage in AWS is a logical reference to a lifecycle state of an API (such as beta or production). When you deploy an API, you deploy it to a specific stage.
What is the function of custom domains in AWS API Gateway?
Custom domains in AWS API Gateway allow you to map specific domains of your web service’s API calls to a specific stage in your REST or HTTP APIs.
What information do you need to set up a custom domain name for API Gateway?
To set up a custom domain name for API Gateway, you need the following: a domain name purchased from a domain name provider, a certificate to validate your ownership of the domain, and a hosted zone ID for the record set that you want to route traffic to.
How can you manage application lifecycle with stages in AWS API Gateway?
In AWS API Gateway, you can use stages to manage your application lifecycle by designating different stages for different environments, such as development, testing, and production. You can then deploy your APIs to these specific stages.
Is it possible to use the same custom domain name across multiple stages in AWS API Gateway?
No, a custom domain name must be unique across all stages within a region in AWS API Gateway.
Can we use wildcard custom domain names in AWS API Gateway?
Yes, wildcard custom domain names can be used in API Gateway. However, they need to be validated with an ACM certificate.
What can you configure using the API Gateway console when you create a new API stage?
When creating a new API stage in API Gateway, you can configure a variety of settings such as stage name, deployment description, access logs/tracing settings, canary release settings, and stage variables.
What are stage variables in AWS API Gateway and what is their function?
Stage variables are name-value pairs that you can define as configuration attributes associated with a deployment stage of a REST API in AWS API Gateway. They act like environment variables and can be used to change the behavior of the API Gateway for each deployment stage.
How does the Base Path Mapping work in AWS API Gateway?
Base Path Mapping in AWS API Gateway helps you to route requests to the appropriate APIs and stages in the API Gateway based on the base path in the request URL. For example, you can configure your API to route requests with “/v1” in the URL to the “v1” deployment stage of your API.
What are some of the benefits of using an API Gateway custom domain name?
Some of the benefits of using an API Gateway custom domain name include: easy route configuration, cleaner API URLs, seamless integration with AWS services like Route53 and ACM, and it eliminates the need to manage the API stage in your client applications.
What does the Canary Release deployment method do in API Gateway?
The Canary Release method in API Gateway allows you to test a new API version in the production environment with a small portion of the traffic, before fully deploying it. This reduces the risk of deploying an API that may cause issues.
Can we use AWS Certificate Manager (ACM) to manage our custom domain certificates in API Gateway?
Yes, we can use AWS Certificate Manager (ACM) to create and manage the SSL/TLS certificates required for custom domain names in API Gateway.
How can we control access to API Gateway stages?
We can control access to API Gateway stages using a variety of means such as IAM roles and policies, Cognito user pools, AWS Organizations, resource policies, and custom authorizers.
What happens when you delete an API Gateway stage?
When you delete a stage in API Gateway, the stage and all of its settings are removed from the API Gateway service. The API resources and methods are not affected, but the API is no longer accessible at the stage’s API Gateway service endpoint.
Can we roll back an API Deployment to a previous stage in AWS API Gateway?
Yes, we can roll back an API Deployment to a previous stage in AWS API gateway by creating a new deployment pointing to the older stage.