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.

[cloudwatch] position of the widget in a dashboard cannot be changed

See original GitHub issue

Description of the bug

The position of the widget in the cloudwatch dashboard cannot be changed using the method described in the documentation.

Reproduction Steps

    initApiErrorWidgget(apiGateways: ApiGatewayConfig[]): cloudwatch.IWidget {
        let let apiErrorWidget = new cloudwatch.GraphWidget({
        // implem details
        })
        return apiErrorWidget;
    }


    constructor(scope: cdk.Construct, id: string, props: GlobalDashboardConfig) {
        super(scope, id);

        let globalDashboard = new cloudwatch.Dashboard(this, "globalDashboard", {
            dashboardName: props.name,
        })
        let apiErrorWidget = this.initApiErrorWidgget(props.apiGateways)
        globalDashboard.addWidgets(apiErrorWidget)
        apiErrorWidget.position(9, 0)
    }

Environment

  • **CLI Version :1.50.0
  • **Framework Version:1.50.0
  • **Node.js Version:v12.18.1
  • **OS :Darwin
  • **Language (Version):TypeScript (3.9.6)

This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jain98commented, Nov 17, 2020

Instead of hard-coding position using the position method inherited from the ConcreteWidget class a workaround and probably easier way to position widgets is to use Columns and Rows which can be used to set the widgets matrix in a dashboard.

Example usage -

        const dashboard = new Dashboard(this, "dashboard", {
            dashboardName: "foo",
            widgets: [
                [
                    new Column(widget1),
                    new Column(widget2, widget3, widget4)
                    new Column(widget5, widget6, widget7)
                ],
                [
                    widget8
                ],
                [
                    widget9,
                    widget10
                ]
            ]
        });
2reactions
peterwoodworthcommented, May 19, 2021

We’ve identified where the problem is.

The L2 construct is building a CfnDashboard object. In Cloudformation docs, widgets in the dashboard are built with a string. The CDK is building that string on line 101:

https://github.com/aws/aws-cdk/blob/6179ac16f2fcab5bf5e03a3629db281018d7585b/packages/%40aws-cdk/aws-cloudwatch/lib/dashboard.ts#L95-L109

Widgets are imported into that dashboard via rows:

https://github.com/aws/aws-cdk/blob/6179ac16f2fcab5bf5e03a3629db281018d7585b/packages/%40aws-cdk/aws-cloudwatch/lib/dashboard.ts#L125-L132

These widgets are turned into strings via the Column object as seen on line 99 of the first snippet. However, column position is adjusted in the following line.

And as you can see here:

https://github.com/aws/aws-cdk/blob/6179ac16f2fcab5bf5e03a3629db281018d7585b/packages/%40aws-cdk/aws-cloudwatch/lib/layout.ts#L83-L89

When column position is adjusted, it adjusts the position of individual widgets as well, thereby always setting them to 0.

We are investigating a possible fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

Move or resize a graph on a CloudWatch dashboard
In the navigation pane, choose Dashboards, and then choose a dashboard. Select the graph. Alternatively, hover over the title of the graph and...
Read more >
Cannot edit AWS Dashboard widgets with green borders
Recently I came across some widgets that I cannot edit (though it does allow me to delete...). These widgets have a green border,...
Read more >
PutDashboard - Amazon CloudWatch - 亚马逊云科技
Creates a dashboard if it does not already exist, or updates an existing dashboard. If you update a dashboard, the entire contents are...
Read more >
How To Create a CloudWatch Dashboard - YouTube
Cloud dashboards are essential in providing visibility into the health of a system. Cloudwatch is a monitoring service in AWS that makes it ......
Read more >
Creating a Cloudwatch Dashboard to Monitor Distributed ...
On your Cloudwatch Dashboard, click the Add widget button. Select Line => Metrics => EC2 Spot => Fleet Request Metrics. Search for “Fulfilled” ......
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