Setting stage variables using the Amazon API Gateway console - Amazon API Gateway

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:

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.

  3. Choose Deploy API. Choose New Stage and enter "beta" for Stage name. Choose Deploy.

  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 preceding 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 expands the given stage variable into an ARN.

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

  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.