API Gateway 中的 HTTP API 的 API Gateway 阶段变量引用
在以下情况下,您可以对 HTTP API 使用 API Gateway 阶段变量。
HTTP 集成 URI
您可将阶段变量用作 HTTP 集成 URI 的一部分,如以下示例所示。
-
不带协议的完整 URI –
http://${stageVariables.<variable_name>} -
完整域 –
http://${stageVariables.<variable_name>}/resource/operation -
子域 –
http://${stageVariables.<variable_name>}.example.com/resource/operation -
路径 –
http://example.com/${stageVariables.<variable_name>}/bar -
查询字符串 –
http://example.com/foo?q=${stageVariables.<variable_name>}
Lambda 函数
您可以使用阶段变量代替 Lambda 函数集成名称或别名,如以下示例所示。
-
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account_id>:function:${stageVariables.<function_variable_name>}/invocations -
arn:aws:apigateway:<region>:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account_id>:function:<function_name>:${stageVariables.<version_variable_name>}/invocations
注意
要将阶段变量用于 Lambda 函数,该函数必须与 API 位于同一账户中。阶段变量不支持跨账户 Lambda 函数。
Amazon 集成凭证
您可以在 Amazon 用户或角色凭证 ARN 中使用阶段变量,如以下示例所示。
-
arn:aws:iam::<account_id>:${stageVariables.<variable_name>}