Amazon API Gateway stage variables reference - Amazon API Gateway
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Amazon API Gateway stage variables reference

You can use API Gateway stage variables in the following cases.

Parameter mapping expressions

A stage variable can be used in a parameter mapping expression for an API method's request or response header parameter, without any partial substitution. In the following example, the stage variable is referenced without the $ and the enclosing {...}.

  • stageVariables.<variable_name>

Mapping templates

A stage variable can be used anywhere in a mapping template, as shown in the following examples.

  • { "name" : "$stageVariables.<variable_name>"}

  • { "name" : "${stageVariables.<variable_name>}"}

HTTP integration URIs

A stage variable can be used as part of an HTTP integration URL, as shown in the following examples:

  • A full URI without protocol – http://${stageVariables.<variable_name>}

  • A full domain – http://${stageVariables.<variable_name>}/resource/operation

  • A subdomain – http://${stageVariables.<variable_name>}.example.com/resource/operation

  • A path – http://example.com/${stageVariables.<variable_name>}/bar

  • A query string – http://example.com/foo?q=${stageVariables.<variable_name>}

Amazon integration URIs

A stage variable can be used as part of Amazon URI action or path components, as shown in the following example.

  • arn:aws:apigateway:<region>:<service>:${stageVariables.<variable_name>}

Amazon integration URIs (Lambda functions)

A stage variable can be used in place of a Lambda function name, or version/alias, as shown in the following examples.

  • 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

Note

To use a stage variable for a Lambda function, the function must be in the same account as the API. Stage variables don't support cross-account Lambda functions.

Amazon integration credentials

A stage variable can be used as part of Amazon user/role credential ARN, as shown in the following example.

  • arn:aws:iam::<account_id>:${stageVariables.<variable_name>}