import {App} from "monocdk"; import...

5/12/2021  •  57 views
import {App} from "monocdk";
import {CfnDashboard, Dashboard, IWidget} from "monocdk/aws-cloudwatch";
import {DeploymentStack, SoftwareType, DeploymentEnvironment} from "@amzn/pipelines";

export interface CloudWatchStackProps {
readonly env: DeploymentEnvironment;
readonly stackName?: string;
readonly stage: string;
readonly dashboardName: string;
readonly dashboardBody: string;
readonly softwareType: string;
readonly widgets: IWidget[];

}

export class CloudWatchDashboardStack extends DeploymentStack {
constructor(app: App, id: string, props: CloudWatchStackProps) {
super(app, id, {
env: props.env,
softwareType: SoftwareType.INFRASTRUCTURE,
stackName: props.stackName,
});
if(props.dashboardBody && props.dashboardBody.length>0){
new CfnDashboard(this, props.dashboardName, {
dashboardName: props.dashboardName,
dashboardBody: props.dashboardBody
});
} else if(props.widgets && props.widgets.length>0){
const dashboard = new Dashboard(this, props.dashboardName,{
dashboardName: props.dashboardName,
})
dashboard.addWidgets(...props.widgets);
}
}
}
https://paste.ac/9coYk6x