Grafana Cloud Enterprise Open source

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.

Variable typeSupported
QueryYes
CustomYes
Data sourceYes

Create a query variable

To create a query variable:

  1. Navigate to Dashboard settings > Variables.
  2. Click Add variable.
  3. Select Query as the variable type.
  4. Select the Amazon Athena data source.
  5. 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

SQL
SELECT DISTINCT region FROM my_table

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

SQL
SELECT hostname AS text, id AS value FROM my_table

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

SQL
SELECT time, value
FROM my_table
WHERE region = '$region'
ORDER BY time ASC

Template variables are also supported in the query editor’s resource selectors (Region, Catalog, Database, Table, and Column drop-downs).

Next steps