question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cw.Dashboard method addWidgets(...widgets: IWidget[])) doesn't take an already formed array of GraphWidgets/TextWidgets/AlarmWidgets

See original GitHub issue
this.Dashboard.addWidgets(
      new cw.TextWidget({
        markdown:
          "# Hello World!!!",
        width: 24
      }),
    new cw.GraphWidget({
    <SOMETHING>
   }),
   new cw.AlarmWidget({
    <SOMETHING>
   }),
)

In the above addWidgets() method I want to add an array i.e GraphWidget[] or AlarmWidget[]

Currently I can’t really add the previously formed GraphWidget[] or AlarmWidget[] directly into the method. as It can only take IWidget[]. Whereas it should consider AlarmWidget[] or GraphWidget[] as IWidget[] but it is not doing that.

So need a way so that I can pass the array of AlarmWidgets or GraphWidgets directly into addWidgets() method.

Use Case

Lets take an example. You have your service deployed into 3 different Availability Zones. Now you created 3 different CloudWatch Alarms for each of the Availability Zones. Now you named those 3 alarms programmatically

cw.Alarm[] myAlarmsArray = vpc.availabilityZones.map(
      (azs, index) =>
        new cw.Alarm(this, "MyAlarm" + index, {
          alarmName: "Too Many Unhealthy Hosts_" + azs,
          alarmDescription: "MyAlarms per AZ",
});

Now that you have an array of alarms i.e myAlarmsArray, you can easily create an AlarmsWidgets[] using below sort of code i.e myAlarmsWidgets = myAlarmsArray.map( new AlarmsWidget())

so you now have the array of AlarmWidgets[] created through code. and you want to show their status on CloudWatch dashboard. All you have to do is add the AlarmWidgets[] directly into your dashboard’s addWidgets() method. Which is not possible currently.

It will be hard to create those AlarmWidgets one by one and add one by one into addWidgets() method.

Proposed Solution

Technically AlarmWidget[] or GraphWidget[] arrays should be considered as IWidget[] array but it is not doing that.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kushg18commented, Oct 26, 2020

I’m having the same issue. dashboard.addWidgets(...IWidget[]) does not expect any ConcreteWidget, for example GraphWidget.

The only way to byepass this is to actually make use of IWidget instead of using GraphWidget or possibly any other concrete widget.

Error:

[
  {
    "dataPath": "/widgets/1/properties",
    "message": "Should have required property 'metrics'"
  },
  {
    "dataPath": "/widgets/1/properties",
    "message": "The metric widget should have specified a region and a data source or an alarm annotation"
  },
  {
    "dataPath": "/widgets/1/properties",
    "message": "Should have required property 'annotations'"
  }
]
0reactions
mingfancommented, Jun 16, 2022

Have similar issue,

dashboard.addWidgets(new GraphWidget({ title: metricName, left: myMetrics, leftYAxis: { label: unitDescription, showUnits: false, }, }) )

where myMetrics is IMetric[], but the Widget only display the 1st one in the myMetrics.

@rix0rrr Can you please reopen this one

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dashboard Body Structure and Syntax - Amazon CloudWatch
A DashboardBody is a string in JSON format. It can include an array of between 0 and 500 widget objects, as well as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found