[cloudwatch] position of the widget in a dashboard cannot be changed
See original GitHub issueDescription 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:
- Created 3 years ago
- Reactions:2
- Comments:12 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 -
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