Skip to content

Resource: awsCloudwatchQueryDefinition

Provides a CloudWatch Logs query definition resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.cloudwatchQueryDefinition.CloudwatchQueryDefinition(this, "example", {
  logGroupNames: ["/aws/logGroup1", "/aws/logGroup2"],
  name: "custom_query",
  queryString:
    "fields @timestamp, @message\n| sort @timestamp desc\n| limit 25\n",
});

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the query.
  • queryString - (Required) The query to save. You can read more about CloudWatch Logs Query Syntax in the documentation.
  • logGroupNames - (Optional) Specific log groups to use with the query.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • queryDefinitionId - The query definition ID.

Import

CloudWatch query definitions can be imported using the query definition ARN. The ARN can be found on the "Edit Query" page for the query in the AWS Console.

$ terraform import aws_cloudwatch_query_definition.example arn:aws:logs:us-west-2:123456789012:query-definition:269951d7-6f75-496d-9d7b-6b7a5486bdbd