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, and then create a GET method on the API's root resource. Set the integration type to HTTP and set the Endpoint URL to http://${stageVariables.url}.

  3. Deploy the API to a new stage named beta.

  4. In the main navigation pane, choose Stages, and then select the beta stage.

  5. On the Stage variables tab, choose Edit.

  6. Choose Add stage variable.

  7. For Name, enter url. For value, enter httpbin.org/get.

  8. Choose Add stage variable, and then do the following:

    For Name, enter stageName. For value, enter beta.

  9. Choose Add stage variable, and then do the following:

    For Name, enter function. For value, enter HelloWorld.

    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.

  10. Choose Save.

  11. 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.

  12. 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, and HelloEveryone), respectively.

    To learn how to use stage variables, see Using Amazon API Gateway stage variables.