DynamoDB template variables
Use template variables to create dynamic, reusable dashboards that let you change query parameters without editing individual panels. For general information about template variables, refer to Templates and variables.
Before you begin
Supported variable types
The DynamoDB data source supports the following variable types:
Create a query variable
The variable query editor uses the same PartiQL code editor as the main query editor.
To create a query variable:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the DynamoDB data source.
- Enter a PartiQL query in the query editor.
- Click Run query to preview the values.
Caution
Variable queries run each time the variable is refreshed. A
SELECTwithout a partition key in theWHEREclause results in a full table scan. Use targeted queries to avoid excessive read capacity consumption.
Query return format
The query editor determines variable values based on the number of columns your query returns:
Single-column example
This query returns a list of unique customer IDs for use as variable values:
SELECT DISTINCT customerId FROM "orders"Each customerId value becomes both the display text and the substituted value.
Two-column example
This query returns an ID and a human-readable name:
SELECT sensorId, sensorName FROM "sensors"The variable drop-down displays sensorName values, but the selected sensorId is substituted into queries.
Use variables in queries
Reference template variables in your PartiQL queries using the $variable or ${variable} syntax. Single-value variables are substituted as-is, so you must include quotes around string values in your query:
SELECT * FROM "orders" WHERE customerId = '$customer'Or with the braced syntax:
SELECT timestamp AS time, metric_value
FROM "metrics"
WHERE sensorId = '${sensor}'
ORDER BY timestampFor numeric values, omit the quotes:
SELECT * FROM "orders" WHERE orderTotal > $thresholdMulti-value variables
When a variable allows multiple selections, the DynamoDB data source formats the values as a comma-separated, single-quoted list. For example, if a user selects A, B, and C, the variable expands to 'A','B','C'.
Use multi-value variables with the IN operator:
SELECT * FROM "orders" WHERE status IN ($status)If the user selects pending and shipped, this expands to:
SELECT * FROM "orders" WHERE status IN ('pending','shipped')Next steps
- Learn how to write queries in the DynamoDB query editor.
- Set up alerting based on DynamoDB data.


