Setting stage variables using the Amazon API Gateway console
In this tutorial, you learn how to set stage variables for two deployment stages of a sample API by using the Amazon API Gateway console. Before you begin, make sure the following prerequisites are met:
-
You must have an API available in API Gateway. Follow the instructions in Creating a REST API in Amazon API Gateway.
-
You must have deployed the API at least once. Follow the instructions in Deploying a REST API in Amazon API Gateway.
-
You must have created the first stage for a deployed API. Follow the instructions in Create a new stage.
To declare stage variables using the API Gateway console
Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway
. -
Create an API, and then create a
GET
method on the API's root resource. Set the integration type to HTTP and set the Endpoint URL tohttp://${stageVariables.url}
. -
Deploy the API to a new stage named
beta
. -
In the main navigation pane, choose Stages, and then select the beta stage.
-
On the Stage variables tab, choose Edit.
-
Choose Add stage variable.
-
For Name, enter
url
. For value, enterhttpbin.org/get
. -
Choose Add stage variable, and then do the following:
For Name, enter
stageName
. For value, enterbeta
. -
Choose Add stage variable, and then do the following:
For Name, enter
function
. For value, enterHelloWorld
.Note
When setting a Lambda function as the value of a stage variable, use the function's local name, possibly including its alias or version specification, as in
HelloWorld
,HelloWorld:1
orHelloWorld:alpha
. Do not use the function's ARN (for example,arn:aws:lambda:us-east-1:123456789012:function:HelloWorld
). The API Gateway console assumes the stage variable value for a Lambda function as the unqualified function name and expands the given stage variable into an ARN. -
Choose Save.
-
Now create a second stage. From the Stages navigation pane, choose Create stage. For Stage name, enter
prod
. Select a recent deployment from Deployment, and then choose Create stage. -
As with the beta stage, set the same three stage variables (url, stageName, and function) to different values (
petstore-demo-endpoint.execute-api.com/petstore/pets
,prod
, andHelloEveryone
), respectively.To learn how to use stage variables, see Using Amazon API Gateway stage variables.