Skip to content

metrics: Validate parameters for a Metric.dimensionsΒ #3116

@cybergoof

Description

@cybergoof
  • I'm submitting a ...

    • πŸͺ² bug report
    • [ x ] πŸš€ feature request
    • πŸ“š construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    When creating a new Metric for a CloudWatch dashboard, an 'undefined' is accepted for the dimensions value, but CloudFormation will reject it.

  • What is the expected behavior (or behavior of feature suggested)?
    CDK should evaluate the name/value of a dimension and reject invalid values.

  • What is the motivation / use case for changing the behavior or adding this feature?
    Input validation at the CDK build process is better than waiting for CloudFormation.

  • Please tell us about your environment:

    • CDK CLI Version: 0.35.0
    • Module Version: 0.35.0
    • OS: [all ]
    • Language: [TypeScript]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

        const dashboard = new cloudwatch.Dashboard(this, name, { dashboardName: name});
        const newMetric = new Metric({
            dimensions: {
                AutoScalingGroupName: undefined,
            },
            metricName: "CPUUtilization",
            namespace: "AWS/EC2",
            statistic: "avg",
        });
        dashboard.addWidgets(
            new GraphWidget({
                left: [
                    newMetric,
                ],
                title: `Average CPU`,
           }),
        );
    }

The above will build. But the following error is given from CloudFormation

The dashboard body is invalid, there are 1 validation errors: [ { "dataPath": "/widgets/0/properties/metrics/0", "message": "Should NOT have more than 3 items" } ] (Service: AmazonCloudWatch; Status Code: 400; Error Code: InvalidParameterInput; 

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-cloudwatchRelated to Amazon CloudWatcheffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions