API Gateway Stage variables

  • Stage variables are name-value pairs that you can define as configuration attributes associated with a deployment stage of a REST API. They act like environment variables and can be used in your API setup and mapping templates.
  • For example, you can define a stage variable in a stage configuration, and then set its value as the URL string of an HTTP integration for a method in your REST API. Later, you can reference the URL string using the associated stage variable name from the API setup. This way, you can use the same API setup with a different endpoint at each stage by resetting the stage variable value to the corresponding URLs. You can also access stage variables in the mapping templates, or pass configuration parameters to your AWS Lambda or HTTP backend.
  • 阶段变量是您可以定义为与 REST API 部署阶段关联的配置属性的名称-值对。它们与环境变量的功能类似,可用于 API 设置和映射模板。
  • 例如,您可以在阶段配置中定义一个阶段变量,然后针对 REST API 中的方法将其值设置为 HTTP 集成的 URL 字符串。之后,您可以使用 API 设置中的关联阶段变量名称引用该 URL 字符串。这样一来,您就可以通过将阶段变量值重置为相应的 URL,在每个阶段对不同终端节点使用同一 API 设置。此外,您还可以访问映射模板中的阶段变量,或者将配置参数传递给 AWS Lambda 或 HTTP 后端。
  • 有关映射模板的更多信息,请参阅API Gateway 映射模板和访问日志记录变量引用

相关文章