@@ -13,6 +13,8 @@ import { InstanceDrainHook } from './drain-hook/instance-drain-hook';
13
13
import { ECSMetrics } from './ecs-canned-metrics.generated' ;
14
14
import { CfnCluster , CfnCapacityProvider , CfnClusterCapacityProviderAssociations } from './ecs.generated' ;
15
15
16
+ const CLUSTER_SYMBOL = Symbol . for ( '@aws-cdk/aws-ecs/lib/cluster.Cluster' ) ;
17
+
16
18
/**
17
19
* The properties used to define an ECS cluster.
18
20
*/
@@ -94,6 +96,14 @@ export enum MachineImageType {
94
96
* A regional grouping of one or more container instances on which you can run tasks and services.
95
97
*/
96
98
export class Cluster extends Resource implements ICluster {
99
+
100
+ /**
101
+ * Return whether the given object is a Cluster
102
+ */
103
+ public static isCluster ( x : any ) : x is Cluster {
104
+ return x !== null && typeof ( x ) === 'object' && CLUSTER_SYMBOL in x ;
105
+ }
106
+
97
107
/**
98
108
* Import an existing cluster to the stack from its attributes.
99
109
*/
@@ -679,6 +689,12 @@ export class Cluster extends Resource implements ICluster {
679
689
}
680
690
}
681
691
692
+ Object . defineProperty ( Cluster . prototype , CLUSTER_SYMBOL , {
693
+ value : true ,
694
+ enumerable : false ,
695
+ writable : false ,
696
+ } ) ;
697
+
682
698
/**
683
699
* A regional grouping of one or more container instances on which you can run tasks and services.
684
700
*/
@@ -1259,7 +1275,7 @@ class MaybeCreateCapacityProviderAssociations implements IAspect {
1259
1275
}
1260
1276
1261
1277
public visit ( node : IConstruct ) : void {
1262
- if ( node instanceof Cluster ) {
1278
+ if ( Cluster . isCluster ( node ) ) {
1263
1279
if ( ( this . scope . defaultCapacityProviderStrategy . length > 0 || this . scope . capacityProviderNames . length > 0 && ! this . resource ) ) {
1264
1280
this . resource = new CfnClusterCapacityProviderAssociations ( this . scope , this . id , {
1265
1281
cluster : node . clusterName ,
0 commit comments