AWS Certified Developer - Associate | Managing Backend Endpoints in Amazon API Gateway

Managing Backend Endpoints in Amazon API Gateway

Prev Question Next Question

Question

A developer is using Amazon API Gateway as an HTTP proxy to a backend endpoint.

There are three separate environments: Development, Testing, Production, and three corresponding stages in the API gateway. How should traffic be directed to different backend endpoints for each of these stages without creating a separate API for each?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - B.

The AWS Documentation mentions the following to support this.

Stage variables are name-value pairs that you can define as configuration attributes associated with a deployment stage of an API.

They act like environment variables and can be used in your API setup and mapping templates.

Option A is incorrect since this would only allow for additions of schema's.

Option C is incorrect since this is only used for Authorization and would not help differentiate the environments.

Option D is incorrect since this would help in integrating the responses to the API gateway.

For more information on Stage variables in the API gateway, please refer to the below Link-

https://docs.aws.amazon.com/apigateway/latest/developerguide/stage-variables.html

Option B is the correct answer.

Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. It enables developers to build scalable and secure APIs quickly and easily.

In this scenario, the developer is using Amazon API Gateway as an HTTP proxy to a backend endpoint, and there are three separate environments: Development, Testing, Production, and three corresponding stages in the API gateway. The requirement is to direct traffic to different backend endpoints for each of these stages without creating a separate API for each.

To achieve this, the developer can use stage variables and configure the stage variables in the HTTP integration Request of the API. A stage variable is a name-value pair that is associated with a specific stage of an API. By using stage variables, the developer can specify different backend endpoints for each stage.

Here are the steps to follow to use stage variables:

  1. Create stage variables: In the API Gateway console, navigate to the stage you want to configure, select the Stage Variables tab, and add the required variables.

  2. Configure stage variables in the HTTP integration Request: In the Integration Request panel of the API Gateway console, specify the backend endpoint using the stage variable, for example, ${stageVariables.backendEndpoint}.

  3. Deploy the API: After configuring the stage variables, deploy the API to the corresponding stage.

Once the API is deployed, traffic will be directed to the appropriate backend endpoint based on the stage variable configuration.

Option A is incorrect because adding a model to the API and adding a schema to differentiate different backend endpoints is not a valid solution to direct traffic to different backend endpoints for each stage.

Option C is incorrect because using API Custom Authorizers to create an authorizer for each of the different stages is not relevant to the requirement to direct traffic to different backend endpoints for each stage.

Option D is incorrect because updating the Integration Response of the API to add different backend endpoints is not a valid solution to direct traffic to different backend endpoints for each stage.