# LogQueryWidgetProps

Properties for a Query widget.

Used as props by: [LogQueryWidget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.LogQueryWidget.html)

- Source: [`aws-cloudwatch/lib/log-query.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-cloudwatch/lib/log-query.ts#L45)
- Type last changed: v2.205.0 · 15 Jul 2025

## Example

TypeScript:

```ts
declare const dashboard: cloudwatch.Dashboard;

dashboard.addWidgets(new cloudwatch.LogQueryWidget({
  logGroupNames: ['my-log-group'],
  view: cloudwatch.LogQueryVisualizationType.TABLE,
  // The lines will be automatically combined using '\n|'.
  queryLines: [
    'fields @message',
    'filter @message like /Error/',
  ]
}));
```

Python:

```python
# dashboard: cloudwatch.Dashboard

dashboard.add_widgets(cloudwatch.LogQueryWidget(
    log_group_names=["my-log-group"],
    view=cloudwatch.LogQueryVisualizationType.TABLE,
    # The lines will be automatically combined using '\n|'.
    query_lines=["fields @message", "filter @message like /Error/"
    ]
))
```

Java:

```java
Dashboard dashboard;

dashboard.addWidgets(LogQueryWidget.Builder.create()
        .logGroupNames(List.of("my-log-group"))
        .view(LogQueryVisualizationType.TABLE)
        // The lines will be automatically combined using '\n|'.
        .queryLines(List.of("fields @message", "filter @message like /Error/"))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Dashboard dashboard;

dashboard.AddWidgets(new LogQueryWidget(new LogQueryWidgetProps {
    LogGroupNames = new [] { "my-log-group" },
    View = LogQueryVisualizationType.TABLE,
    // The lines will be automatically combined using '\n|'.
    QueryLines = new [] { "fields @message", "filter @message like /Error/" }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var dashboard Dashboard

dashboard.AddWidgets(cloudwatch.NewLogQueryWidget(&LogQueryWidgetProps{
	LogGroupNames: []*string{
		jsii.String("my-log-group"),
	},
	View: cloudwatch.LogQueryVisualizationType_TABLE,
	// The lines will be automatically combined using '\n|'.
	QueryLines: []*string{
		jsii.String("fields @message"),
		jsii.String("filter @message like /Error/"),
	},
}))
```

## Properties

- `accountId`: string — The AWS account ID where the log groups are located.

  **Default:** Current account

  This enables cross-account functionality for CloudWatch dashboards.
  Before using this feature, ensure that proper cross-account sharing is configured
  between the monitoring account and source account.

  For more information, see:
  https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html

- `height`: number = 6 — Height of the widget.

- `logGroupNames`: string[] (required) — Names of log groups to query.

- `queryLanguage`: [LogQueryLanguage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.LogQueryLanguage.html) = LogQueryLanguage.LOGS_INSIGHTS — The query language to use for the query.

- `queryLines`: string[] — A sequence of lines to use to build the query.

  **Default:** Exactly one of `queryString`, `queryLines` is required.

  The query will be built by joining the lines together using `\n|`.

- `queryString`: string — Full query string for log insights.

  **Default:** Exactly one of `queryString`, `queryLines` is required.

  Be sure to prepend every new line with a newline and pipe character
  (`\n|`).

- `region`: string — The region the metrics of this widget should be taken from.

  **Default:** Current region

- `title`: string — Title for the widget.

  **Default:** No title

- `view`: [LogQueryVisualizationType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.LogQueryVisualizationType.html) = LogQueryVisualizationType.TABLE — The type of view to use.

- `width`: number = 6 — Width of the widget, in a grid of 24 units wide.
