2022-11-01 23:22:06 +08:00
---
aliases:
2022-12-10 00:36:04 +08:00
- ../../data-sources/aws-cloudwatch/template-variables/
- template-queries-cloudwatch/
2022-11-01 23:22:06 +08:00
description: Guide on using template variables in CloudWatch queries
keywords:
- grafana
- aws
- cloudwatch
- templates
- variables
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- cloud
- enterprise
- oss
2022-11-01 23:22:06 +08:00
menuTitle: Template variables
title: CloudWatch template variables
2025-10-08 03:21:44 +08:00
weight: 300
2024-05-28 22:17:49 +08:00
refs:
variable-syntax:
- pattern: /docs/grafana/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/variable-syntax/
- pattern: /docs/grafana-cloud/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/variable-syntax/
add-template-variables:
- pattern: /docs/grafana/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/add-template-variables/
- pattern: /docs/grafana-cloud/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/add-template-variables/
variables:
- pattern: /docs/grafana/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/
- pattern: /docs/grafana-cloud/
destination: /docs/grafana/< GRAFANA_VERSION > /dashboards/variables/
2022-11-01 23:22:06 +08:00
---
# CloudWatch template variables
Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
2025-10-08 03:21:44 +08:00
Grafana lists these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard, and they are called template variables
2022-11-01 23:22:06 +08:00
2025-10-08 03:21:44 +08:00
<!-- Grafana refers to such variables as template variables. -->
For an introduction to templating and template variables, refer to [Templating ](ref:variables ) and [Add and manage variables ](ref:add-template-variables ).
2022-11-01 23:22:06 +08:00
## Use query variables
You can specify these CloudWatch data source queries in the Variable edit view's **Query Type** field.
Use them to fill a variable's options list with values like `regions` , `namespaces` , `metric names` , and `dimension keys/values` .
| Name | List returned |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Regions** | All AWS regions. |
| **Namespaces** | All namespaces CloudWatch supports. |
| **Metrics** | Metrics in the namespace. (Specify region or use "default" for custom metrics.) |
| **Dimension Keys** | Dimension keys in the namespace. |
| **Dimension Values** | Dimension values matching the specified `region` , `namespace` , `metric` , and `dimension_key` . Use dimension `filters` for more specific results. |
| **EBS Volume IDs** | Volume ids matching the specified `region` and `instance_id` . |
| **EC2 Instance Attributes** | Attributes matching the specified `region` , `attribute_name` , and `filters` . |
| **Resource ARNs** | ARNs matching the specified `region` , `resource_type` , and `tags` . |
| **Statistics** | All standard statistics. |
| **LogGroups** | All log groups matching the specified `region` . |
For details on the available dimensions, refer to the [CloudWatch Metrics and Dimensions Reference ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html ).
For details about the metrics CloudWatch provides, refer to the [CloudWatch documentation ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html ).
### Use variables in queries
2025-10-08 03:21:44 +08:00
Use the Grafana variable syntax to include variables in queries. A query variable in dynamically retrieves values from your data source using a query.
2024-05-28 22:17:49 +08:00
For details, refer to the [variable syntax documentation ](ref:variable-syntax ).
2022-11-01 23:22:06 +08:00
## Use ec2_instance_attribute
2025-10-08 03:21:44 +08:00
The `ec2_instance_attribute` function in template variables allows Grafana to retrieve certain instance metadata from the EC2 metadata service, including `Instance ID` and `region` .
2022-11-01 23:22:06 +08:00
### Filters
2025-10-08 03:21:44 +08:00
The `ec2_instance_attribute` query takes a `filters` parameter, where each key is a filter name (such as a tag or instance property), and each value is a comma-separated list of matching values.
2022-11-01 23:22:06 +08:00
You can specify [pre-defined filters of ec2:DescribeInstances ](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html ).
### Select attributes
A query returns only one attribute per instance.
2025-10-08 03:21:44 +08:00
You can select any attribute that has a single value and isn't an object or array, also known as a `flat attribute` :
2022-11-01 23:22:06 +08:00
- `AmiLaunchIndex`
- `Architecture`
- `ClientToken`
- `EbsOptimized`
- `EnaSupport`
- `Hypervisor`
- `IamInstanceProfile`
- `ImageId`
- `InstanceId`
- `InstanceLifecycle`
- `InstanceType`
- `KernelId`
- `KeyName`
- `LaunchTime`
- `Platform`
- `PrivateDnsName`
- `PrivateIpAddress`
- `PublicDnsName`
- `PublicIpAddress`
- `RamdiskId`
- `RootDeviceName`
- `RootDeviceType`
- `SourceDestCheck`
- `SpotInstanceRequestId`
- `SriovNetSupport`
- `SubnetId`
- `VirtualizationType`
- `VpcId`
You can select tags by prepending the tag name with `Tags.` .
For example, select the tag `Name` by using `Tags.Name` .