Amazon Athena template variables
Use template variables to create dynamic, reusable dashboards. Template variables let you parameterize queries so that dashboard viewers can change values without editing the query.
Before you begin
Before you use template variables, ensure you have the following prerequisites.
Supported variable types
The Amazon Athena data source supports the following variable types.
Create a query variable
To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the Amazon Athena data source.
- Enter a SQL query that returns the values you want to use as variable options.
For more information, refer to Add a query variable.
Query examples
Any value queried from an Amazon Athena table can be used as a variable. The following examples show common variable queries.
List distinct values from a column
SELECT DISTINCT region FROM my_tableUse custom display names
To display a custom name for each variable option while using a different value, alias the columns as text and value. The value column must be a string type or cast to a string type.
SELECT hostname AS text, id AS value FROM my_tableUse variables in queries
After creating a variable, reference it in your Amazon Athena queries using
variable syntax. For example, use $variable_name or ${variable_name} in your SQL queries.
SELECT time, value
FROM my_table
WHERE region = '$region'
ORDER BY time ASCTemplate variables are also supported in the query editor’s resource selectors (Region, Catalog, Database, Table, and Column drop-downs).


