Menu
Amazon API Gateway
Developer Guide

Set Stage Variables Using the Amazon API Gateway Console

In this tutorial, you will learn how to set stage variables for two deployment stages of a sample API, using the Amazon API Gateway console.

Prerequisites

  1. You must have an API available in API Gateway. Follow the instructions in Creating an API.

  2. You must have deployed the API at least once. Follow the instructions in Deploying an API.

  3. You must have created the first stage for a deployed API. Follow the instructions in Associate an Existing Deployment with a New stage.

To Declare Stage Variables Using the API Gateway Console

  1. Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.

  2. Create an API, create a GET method on the API's root resource, if you have not already done so. Set the HTTP Endpoint URL value as "http://${stageVariables.url}", and then choose Save.

    
                Set an HTTP GET endpoint URL with a stage variable
  3. Choose Deploy API. Choose New Stage and enter "beta" for Stage name. Choose Deploy.

    
                Deploy to beta stage
  4. In the beta Stage Editor panel; choose the Stage Variables tab; and then choose Add Stage Variable.

  5. Enter the "url" string in the Name field and the "httpbin.org/get" in the Value field. Choose the checkmark icon to save the setting for the stage variable.

  6. Repeat the above step to add two more stage variables: version and function. Set their values as "v-beta" and "HelloWorld", respectively.

    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 or HelloWorld: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 will expand the given stage variable into an ARN.

  7. From the Stages navigation pane, choose Create. For Stage name, type prod. Select a recent deployment from Deployment and then choose Create.

    
                Create a new prod stage for an existing deployment
  8. As with the beta stage, set the same three stage variables (url, version, and function) to different values ("petstore-demo-endpoint.execute-api.com/petstore/pets", "v-prod", and "HelloEveryone"), respectively.

On this page: