cw.Dashboard method addWidgets(...widgets: IWidget[])) doesn't take an already formed array of GraphWidgets/TextWidgets/AlarmWidgets
See original GitHub issuethis.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:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
I’m having the same issue.
dashboard.addWidgets(...IWidget[])
does not expect anyConcreteWidget
, for exampleGraphWidget
.The only way to byepass this is to actually make use of IWidget instead of using GraphWidget or possibly any other concrete widget.
Error:
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