-
Notifications
You must be signed in to change notification settings - Fork 43
/
aspect.ts
108 lines (88 loc) · 3.46 KB
/
aspect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { IAspect } from 'aws-cdk-lib';
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as ecs_patterns from 'aws-cdk-lib/aws-ecs-patterns';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as rds from 'aws-cdk-lib/aws-rds';
import * as stepfunctions from 'aws-cdk-lib/aws-stepfunctions';
import { IConstruct } from 'constructs';
export interface WatchfulAspectProps {
/**
* Automatically watch API Gateway APIs in the scope.
* @default true
*/
readonly apiGateway?: boolean;
/**
* Automatically watch all Amazon DynamoDB tables in the scope.
* @default true
*/
readonly dynamodb?: boolean;
/**
* Automatically watch AWS Lambda functions in the scope.
* @default true
*/
readonly lambda?: boolean;
/**
* Automatically watch AWS state machines in the scope.
* @default true
*/
readonly stateMachine?: boolean;
/**
* Automatically watch RDS Aurora clusters in the scope.
* @default true
*/
readonly rdsaurora?: boolean;
/**
* Automatically watch ApplicationLoadBalanced Fargate Ecs Services in the scope (using ECS Pattern).
* @default true
*/
readonly fargateecs?: boolean;
/**
* Automatically watch ApplicationLoadBalanced EC2 Ecs Services in the scope (using ECS Pattern).
* @default true
*/
readonly ec2ecs?: boolean;
}
/**
* A CDK aspect that can automatically watch all resources within a scope.
*/
export class WatchfulAspect implements IAspect {
/**
* Defines a watchful aspect
* @param watchful The watchful to add those resources to
* @param props Options
*/
constructor(private readonly watchful: Watchful, private readonly props: WatchfulAspectProps = { }) {
}
public visit(node: IConstruct): void {
const watchApiGateway = this.props.apiGateway === undefined ? true : this.props.apiGateway;
const watchDynamo = this.props.dynamodb === undefined ? true : this.props.dynamodb;
const watchLambda = this.props.lambda === undefined ? true : this.props.lambda;
const watchStateMachine = this.props.stateMachine === undefined ? true : this.props.stateMachine;
const watchRdsAuroraCluster = this.props.rdsaurora === undefined ? true : this.props.rdsaurora;
const watchFargateEcs = this.props.fargateecs === undefined ? true : this.props.fargateecs;
const watchEc2Ecs = this.props.ec2ecs === undefined ? true : this.props.ec2ecs;
if (watchApiGateway && node instanceof apigw.RestApi) {
this.watchful.watchApiGateway(node.node.path, node);
}
if (watchDynamo && node instanceof dynamodb.Table) {
this.watchful.watchDynamoTable(node.node.path, node);
}
if (watchLambda && node instanceof lambda.Function) {
this.watchful.watchLambdaFunction(node.node.path, node);
}
if (watchStateMachine && node instanceof stepfunctions.StateMachine) {
this.watchful.watchStateMachine(node.node.path, node);
}
if (watchRdsAuroraCluster && node instanceof rds.DatabaseCluster) {
this.watchful.watchRdsAuroraCluster(node.node.path, node);
}
if (watchFargateEcs && node instanceof ecs_patterns.ApplicationLoadBalancedFargateService) {
this.watchful.watchFargateEcs(node.node.path, node.service, node.targetGroup);
}
if (watchEc2Ecs && node instanceof ecs_patterns.ApplicationLoadBalancedEc2Service) {
this.watchful.watchEc2Ecs(node.node.path, node.service, node.targetGroup);
}
}
}
import { Watchful } from './watchful';