Skip to content
v2.277.0

Dashboard L2 construct ​

A CloudWatch dashboard.

Example ​

ts
import * as cw from 'aws-cdk-lib/aws-cloudwatch';

const dashboard = new cw.Dashboard(this, 'Dash', {
  defaultInterval: Duration.days(7),
  variables: [new cw.DashboardVariable({
    id: 'region2',
    type: cw.VariableType.PATTERN,
    label: 'RegionPattern',
    inputType: cw.VariableInputType.INPUT,
    value: 'us-east-1',
    defaultValue: cw.DefaultValue.value('us-east-1'),
    visible: true,
  })],
});
python
import aws_cdk.aws_cloudwatch as cw


dashboard = cw.Dashboard(self, "Dash",
    default_interval=Duration.days(7),
    variables=[cw.DashboardVariable(
        id="region2",
        type=cw.VariableType.PATTERN,
        label="RegionPattern",
        input_type=cw.VariableInputType.INPUT,
        value="us-east-1",
        default_value=cw.DefaultValue.value("us-east-1"),
        visible=True
    )]
)
java
import software.amazon.awscdk.services.cloudwatch.*;


Dashboard dashboard = Dashboard.Builder.create(this, "Dash")
        .defaultInterval(Duration.days(7))
        .variables(List.of(DashboardVariable.Builder.create()
                .id("region2")
                .type(VariableType.PATTERN)
                .label("RegionPattern")
                .inputType(VariableInputType.INPUT)
                .value("us-east-1")
                .defaultValue(DefaultValue.value("us-east-1"))
                .visible(true)
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.CloudWatch;


var dashboard = new Dashboard(this, "Dash", new DashboardProps {
    DefaultInterval = Duration.Days(7),
    Variables = new [] { new DashboardVariable(new DashboardVariableOptions {
        Id = "region2",
        Type = VariableType.PATTERN,
        Label = "RegionPattern",
        InputType = VariableInputType.INPUT,
        Value = "us-east-1",
        DefaultValue = DefaultValue.Value("us-east-1"),
        Visible = true
    }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"


dashboard := cw.NewDashboard(this, jsii.String("Dash"), &DashboardProps{
	DefaultInterval: awscdk.Duration_Days(jsii.Number(7)),
	Variables: []IVariable{
		cw.NewDashboardVariable(&DashboardVariableOptions{
			Id: jsii.String("region2"),
			Type: cw.VariableType_PATTERN,
			Label: jsii.String("RegionPattern"),
			InputType: cw.VariableInputType_INPUT,
			Value: jsii.String("us-east-1"),
			DefaultValue: cw.DefaultValue_Value(jsii.String("us-east-1")),
			Visible: jsii.Boolean(true),
		}),
	},
})

Initializer ​

ts
new Dashboard(scope: Construct, id: string, props?: DashboardProps)
python
Dashboard(scope: Construct, id: str, props: typing.Optional[DashboardProps] = None)
java
new Dashboard(Construct scope, String id, DashboardProps props)
csharp
new Dashboard(Construct scope, string id, DashboardProps? props = null)
go
NewDashboard(Scope Construct, Id *string, Props DashboardProps)

Construct Props ​

dashboardNameoptionalstringdashboard_nameoptionalstrdashboardNameoptionalStringDashboardNameoptionalstringDashboardNameoptional*string#
Name of the dashboard.

Default: automatically generated name

If set, must only contain alphanumerics, dash (-) and underscore (_)

defaultIntervaloptionalDurationdefault_intervaloptionalDurationdefaultIntervaloptionalDurationDefaultIntervaloptionalDurationDefaultIntervaloptionalDuration#
Interval duration for metrics. You can specify defaultInterval with the relative time (e.g. cdk.Duration.days(7)).

Default: When the dashboard loads, the defaultInterval time will be the default time range.

Both properties defaultInterval and start cannot be set at once.

endoptionalstringendoptionalstrendoptionalStringEndoptionalstringEndoptional*string#
The end of the time range to use for each widget on the dashboard when the dashboard loads.

Default: When the dashboard loads, the end date will be the current time.

If you specify a value for end, you must also specify a value for start. Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z.

periodOverrideoptionalPeriodOverrideperiod_overrideoptionalPeriodOverrideperiodOverrideoptionalPeriodOverridePeriodOverrideoptionalPeriodOverridePeriodOverrideoptionalPeriodOverride= Auto#
Use this field to specify the period for the graphs when the dashboard loads.

Specifying Auto causes the period of all graphs on the dashboard to automatically adapt to the time range of the dashboard. Specifying Inherit ensures that the period set for each graph is always obeyed.

startoptionalstringstartoptionalstrstartoptionalStringStartoptionalstringStartoptional*string#
The start of the time range to use for each widget on the dashboard.

Default: When the dashboard loads, the start time will be the default time range.

notes

You can specify start without specifying end to specify a relative time range that ends with the current time. In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. You can also use start along with an end field, to specify an absolute time range. When specifying an absolute time range, use the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z.

Both properties defaultInterval and start cannot be set at once.

variablesoptionalIVariable[]variablesoptionaltyping.List[IVariable]variablesoptionalList<IVariable>VariablesoptionalIVariable[]Variablesoptional*[]IVariable#
A list of dashboard variables.

Default: No variables

widgetsoptionalIWidget[][]widgetsoptionaltyping.List[typing.List[IWidget]]widgetsoptionalList<List<IWidget>>WidgetsoptionalIWidget[][]Widgetsoptional*[]*[]IWidget#
Initial set of widgets on the dashboard.

Default: No widgets

One array represents a row of widgets.

Properties ​

dashboardArnstringdashboard_arnstrdashboardArnStringDashboardArnstringDashboardArn*string#
ARN of this dashboard.
dashboardNamestringdashboard_namestrdashboardNameStringDashboardNamestringDashboardName*string#
The name of this dashboard.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.

Methods ​

addVariable(variable: IVariable): voiddef add_variable(self, variable: IVariable) -> Nonepublic void addVariable(IVariable variable)public void AddVariable(IVariable variable)func AddVariable(Variable IVariable)#
Add a variable to the dashboard.
addWidgets(...widgets: IWidget[]): voiddef add_widgets(self, widgets: IWidget) -> Nonepublic void addWidgets(IWidget widgets)public void AddWidgets(IWidget widgets)func AddWidgets(Widgets IWidget)#
Add a widget to the dashboard.
notes

Widgets given in multiple calls to add() will be laid out stacked on top of each other.

Multiple widgets added in the same call to add() will be laid out next to each other. However, keep in mind that CloudWatch will vertically compact your dashboard. That means that if there is unused space above a widget, it will be shifted upwards as far as possible to fill that space. Add empty TextWidgets as a spacer in the row above your widgets you need to keep multiple side-by-side widgets consistently spaced.

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.