#!/usr/bin/env node import {App} from 'monocd...

5/12/2021  •  68 views
 
#!/usr/bin/env node
import {App} from 'monocdk';
import {DeploymentPipeline, Platform, SoftwareType} from '@amzn/pipelines';
import {CloudWatchDashboardStack} from './dashboard';
import config from "./config.json";
import {createWidgetsFromJson} from "./metricsutil";
import {CloudWatchDashboardWikiStack} from "./CloudwatchDashboardWikiStack";
import {IWidget} from "monocdk/aws-cloudwatch";
import {getSqsWidgets} from "./top_level_sqs_metrics";
import {getDetailLevelDashboardWidgetsArr} from "./detail_level_dashboard_widgets";
import {IGraphMetric} from "./constants";
import {getStepFunctionDashboardWidgets} from "./top_level_step_functions";


// Set up your CDK App
const app = new App();

const applicationAccount = '450273562952';

const pipeline = new DeploymentPipeline(app, 'Pipeline', {
account: applicationAccount,
pipelineName: 'aakugAWSAnniversaryBillingServiceShadowCDK',
versionSet: 'aakugAWSAnniversaryBillingServiceShadowCDK/development', // The version set you created
versionSetPlatform: Platform.AL2_X86_64,
trackingVersionSet: 'live', // Or any other version set you prefer
bindleGuid: 'amzn1.bindle.resource.akbb5rh5jfs4n3o5bpra',
description: 'A CDK Managed pipeline for AWSAnniversaryBillingServiceShadowCDK',
pipelineId: '3742723',
selfMutate: true,
changeSetApproverProps: {
emailList: 'aakug@amazon.com',
posixApproverGroup: 'caps-orchestration'
},
});
export interface StagePropsInfo {
readonly name: string;
readonly applicationName: string,
readonly accountId: string,
readonly region: string,
readonly stage: string
}

const stageDetails: Array<StagePropsInfo> = [];
config.stageInfo.forEach(info => stageDetails.push(info));
stageDetails.forEach(info => addStageToPipeline(info));

function addStageToPipeline(stageProps: StagePropsInfo) {
const stage = pipeline.addStage(stageProps.name);
const deploymentGroup = stage.addDeploymentGroup({
name: stageProps.applicationName
});

// Detail Level Dashboard
let detailLevelDashboardWidgetsArr : IGraphMetric[] = getDetailLevelDashboardWidgetsArr(stageProps);
const detailedDashboardSource = JSON.stringify({"widgets": createWidgetsFromJson(stageProps, detailLevelDashboardWidgetsArr)});
const detailedDashboardProps = {
env: pipeline.deploymentEnvironmentFor(stageProps.accountId, stageProps.region),
softwareType: SoftwareType.INFRASTRUCTURE,
stage: stageProps.stage,
dashboardName : 'ABAS-detailed-dashboard1-' + stageProps.stage,
dashboardBody: detailedDashboardSource,
widgets: []
};
const detailedDashboardStack = new CloudWatchDashboardStack(
app,
'detailed-dashboard1-' + stageProps.stage,
detailedDashboardProps
);

//Top level dashboard
const topLevelDashboardCloudWatchWidgets:IWidget[] = [...getSqsWidgets(),...getStepFunctionDashboardWidgets(stageProps.region, stageProps.accountId)];

const topLevelDashboardProps = {
env: pipeline.deploymentEnvironmentFor(stageProps.accountId, stageProps.region),
softwareType: SoftwareType.INFRASTRUCTURE,
stage: stageProps.stage,
dashboardName : 'ABAS-top-level-dashboard1-' + stageProps.stage,
dashboardBody: '',
widgets: topLevelDashboardCloudWatchWidgets
};

const topLevelDashboardStack = new CloudWatchDashboardStack(
app,
'top-level-dashboard1-' + stageProps.stage,
topLevelDashboardProps
);

const wikiDashboardProps = {
env: pipeline.deploymentEnvironmentFor(stageProps.accountId, stageProps.region),
softwareType: SoftwareType.INFRASTRUCTURE,
stage: stageProps.stage,
enableEditing: true,
allowCustomWidgets: true,
masterAccountIds: [applicationAccount],
allowLogAccess: true,
roleName: "CloudWatchDashboards",
}

const wikiDashboardStack = new CloudWatchDashboardWikiStack(
app,
'CloudWatchDashboardsWiki-' + stageProps.stage,
wikiDashboardProps
);

deploymentGroup.addStacks(topLevelDashboardStack, detailedDashboardStack, wikiDashboardStack)
}

https://paste.ac/JQCh6LM