CDK - Cloudwatch DashboardVariable in LogQueryWidget

0

Hello,

I'm wondering if it's possible to have a DashboardVariable update a LogQueryWidget in a dashboard. I'm using CDK Typescript fro this.

So far, I've had no luck trying. All other widgets I'm using get updated properly using the dashboard variable.

Sample Code:

const siteVariable = new cloudwatch.DashboardVariable({
      id: 'Site',
      type: cloudwatch.VariableType.PROPERTY,
      label: 'Site',
      value: 'Site',
      values: cloudwatch.Values.fromSearchComponents({
        namespace: MYNAMESPACE,
        metricName: 'MyMetricName',
        dimensions: ['Site'],
        populateFrom: 'Site',
      }),
      visible: true,
      inputType: cloudwatch.VariableInputType.SELECT,
      defaultValue: cloudwatch.DefaultValue.value('All'),
    });
const dashboard = new cloudwatch.Dashboard(this, 'TestDashboard', {
      dashboardName: `TestDashboard-Dashboard`,
      variables: [siteVariable],
    });

const vendorLogQuery = new cloudwatch.LogQueryWidget({
      height: 6,
      width: 24,
      logGroupNames: ['/aws/lambda/MyLambdaFunction'],
      queryString: `fields @timestamp, @message
      | filter @message like "$Site"
      | sort @timestamp desc
      | display @message
      `,
      title: 'Testing - Site Data Logs',
    });
    dashboard.addWidgets(vendorLogQuery);

I've tried numerous variations of the queryString: | filter @message like /$Site/ | filter @message like "Site" and numerous things like siteVariable.toJson() and trying to manipulate that with no results.

I've also tried queryLines with no result:

queryLines: [
        'fields @timestamp, @message',
        'filter @message like /$Site/
        'sort @timestamp desc',
        'display @message',
      ],

I've found no documentation on this, so I assume it's not possible, but I'm hoping someone might have an answer.

1 Answer
1

Hello.

I also tried using the code below, but I couldn't switch the display using the dashboard variable.
Probably, but I was wondering if the log query widget can't be toggled with a dashboard variable.

    const variables = new cw.DashboardVariable({
      id: "functionName",
      type: cw.VariableType.PROPERTY,
      label: "Function",
      inputType: cw.VariableInputType.SELECT,
      value: "FunctionName",
      values: cw.Values.fromSearchComponents({
        namespace: "AWS/Lambda",
        dimensions: ["FunctionName"],
        metricName: "Duration",
        populateFrom: "FunctionName",
      }),
      defaultValue: cw.DefaultValue.FIRST,
      visible: true,
    });

    const dashboard = new Dashboard(this, "SampleLambdaDashboard", {
      dashboardName: "myLambdaDashboard",
      variables: [variables],
    });

    dashboard.addWidgets(
      new TextWidget({
        markdown: `# Dashboard: ${lambdaFunction.functionName}`,
        height: 1,
        width: 24,
      })
    );

    dashboard.addWidgets(
      new LogQueryWidget({
        logGroupNames: [lambdaFunction.logGroup.logGroupName],
        queryLines: [
          "fields @timestamp, @message",
          "sort @timestamp desc",
          "limit 20",
        ],
        width: 24,
      })
    );
  }
}
profile picture
EXPERT
answered 22 days ago
profile picture
EXPERT
reviewed 22 days ago
profile picture
EXPERT
reviewed 22 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions