@@ -5,7 +5,7 @@ import * as ec2 from '../../aws-ec2';
5
5
import * as eks from '../../aws-eks' ;
6
6
import * as iam from '../../aws-iam' ;
7
7
import { IRole } from '../../aws-iam' ;
8
- import { ArnFormat , Duration , ITaggable , Lazy , Resource , Stack , TagManager , TagType , Token } from '../../core' ;
8
+ import { ArnFormat , Duration , ITaggable , Lazy , Resource , Stack , TagManager , TagType , Token , ValidationError } from '../../core' ;
9
9
import { addConstructMetadata , MethodMetadata } from '../../core/lib/metadata-resource' ;
10
10
11
11
/**
@@ -619,10 +619,10 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
619
619
public readonly tags : TagManager = new TagManager ( TagType . MAP , 'AWS::Batch::ComputeEnvironment' ) ;
620
620
621
621
public addInstanceClass ( _instanceClass : ec2 . InstanceClass ) : void {
622
- throw new Error ( `cannot add instance class to imported ComputeEnvironment '${ id } '` ) ;
622
+ throw new ValidationError ( `cannot add instance class to imported ComputeEnvironment '${ id } '` , this ) ;
623
623
}
624
624
public addInstanceType ( _instanceType : ec2 . InstanceType ) : void {
625
- throw new Error ( `cannot add instance type to imported ComputeEnvironment '${ id } '` ) ;
625
+ throw new ValidationError ( `cannot add instance type to imported ComputeEnvironment '${ id } '` , this ) ;
626
626
}
627
627
}
628
628
@@ -650,7 +650,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
650
650
addConstructMetadata ( this , props ) ;
651
651
652
652
this . images = props . images ;
653
- this . allocationStrategy = determineAllocationStrategy ( id , props . allocationStrategy , this . spot ) ;
653
+ this . allocationStrategy = determineAllocationStrategy ( this , props . allocationStrategy , this . spot ) ;
654
654
this . spotBidPercentage = props . spotBidPercentage ;
655
655
656
656
this . spotFleetRole = props . spotFleetRole ?? (
@@ -665,7 +665,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
665
665
( this . instanceClasses . includes ( ec2 . InstanceClass . A1 ) ||
666
666
this . instanceTypes . find ( instanceType => instanceType . sameInstanceClassAs ( ec2 . InstanceType . of ( ec2 . InstanceClass . A1 , ec2 . InstanceSize . LARGE ) ) ) )
667
667
) {
668
- throw new Error ( 'Amazon Linux 2023 does not support A1 instances.' ) ;
668
+ throw new ValidationError ( 'Amazon Linux 2023 does not support A1 instances.' , this ) ;
669
669
}
670
670
671
671
const { instanceRole, instanceProfile } = createInstanceRoleAndProfile ( this , props . instanceRole ) ;
@@ -676,8 +676,8 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa
676
676
this . minvCpus = props . minvCpus ?? DEFAULT_MIN_VCPUS ;
677
677
this . placementGroup = props . placementGroup ;
678
678
679
- validateVCpus ( id , this . minvCpus , this . maxvCpus ) ;
680
- validateSpotConfig ( id , this . spot , this . spotBidPercentage , this . spotFleetRole ) ;
679
+ validateVCpus ( this , this . minvCpus , this . maxvCpus ) ;
680
+ validateSpotConfig ( this , this . spot , this . spotBidPercentage , this . spotFleetRole ) ;
681
681
682
682
const { subnetIds } = props . vpc . selectSubnets ( props . vpcSubnets ) ;
683
683
const resource = new CfnComputeEnvironment ( this , 'Resource' , {
@@ -1010,9 +1010,9 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa
1010
1010
this . eksCluster = props . eksCluster ;
1011
1011
1012
1012
this . images = props . images ;
1013
- this . allocationStrategy = determineAllocationStrategy ( id , props . allocationStrategy , this . spot ) ;
1013
+ this . allocationStrategy = determineAllocationStrategy ( this , props . allocationStrategy , this . spot ) ;
1014
1014
if ( this . allocationStrategy === AllocationStrategy . BEST_FIT ) {
1015
- throw new Error ( `ManagedEc2EksComputeEnvironment '${ id } ' uses invalid allocation strategy 'AllocationStrategy.BEST_FIT'` ) ;
1015
+ throw new ValidationError ( `ManagedEc2EksComputeEnvironment '${ id } ' uses invalid allocation strategy 'AllocationStrategy.BEST_FIT'` , this ) ;
1016
1016
}
1017
1017
this . spotBidPercentage = props . spotBidPercentage ;
1018
1018
this . instanceTypes = props . instanceTypes ?? [ ] ;
@@ -1026,8 +1026,8 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa
1026
1026
this . minvCpus = props . minvCpus ?? DEFAULT_MIN_VCPUS ;
1027
1027
this . placementGroup = props . placementGroup ;
1028
1028
1029
- validateVCpus ( id , this . minvCpus , this . maxvCpus ) ;
1030
- validateSpotConfig ( id , this . spot , this . spotBidPercentage ) ;
1029
+ validateVCpus ( this , this . minvCpus , this . maxvCpus ) ;
1030
+ validateSpotConfig ( this , this . spot , this . spotBidPercentage ) ;
1031
1031
1032
1032
const { subnetIds } = props . vpc . selectSubnets ( props . vpcSubnets ) ;
1033
1033
const resource = new CfnComputeEnvironment ( this , 'Resource' , {
@@ -1179,14 +1179,14 @@ function createSpotFleetRole(scope: Construct): IRole {
1179
1179
} ) ;
1180
1180
}
1181
1181
1182
- function determineAllocationStrategy ( id : string , allocationStrategy ?: AllocationStrategy , spot ?: boolean ) : AllocationStrategy | undefined {
1182
+ function determineAllocationStrategy ( scope : Construct , allocationStrategy ?: AllocationStrategy , spot ?: boolean ) : AllocationStrategy | undefined {
1183
1183
let result = allocationStrategy ;
1184
1184
if ( ! allocationStrategy ) {
1185
1185
result = spot ? AllocationStrategy . SPOT_PRICE_CAPACITY_OPTIMIZED : AllocationStrategy . BEST_FIT_PROGRESSIVE ;
1186
1186
} else if ( allocationStrategy === AllocationStrategy . SPOT_PRICE_CAPACITY_OPTIMIZED && ! spot ) {
1187
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'AllocationStrategy.SPOT_PRICE_CAPACITY_OPTIMIZED' without using spot instances` ) ;
1187
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'AllocationStrategy.SPOT_PRICE_CAPACITY_OPTIMIZED' without using spot instances` , scope ) ;
1188
1188
} else if ( allocationStrategy === AllocationStrategy . SPOT_CAPACITY_OPTIMIZED && ! spot ) {
1189
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'AllocationStrategy.SPOT_CAPACITY_OPTIMIZED' without using spot instances` ) ;
1189
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'AllocationStrategy.SPOT_CAPACITY_OPTIMIZED' without using spot instances` , scope ) ;
1190
1190
}
1191
1191
1192
1192
return result ;
@@ -1200,34 +1200,34 @@ function validateInstances(types?: ec2.InstanceType[], classes?: ec2.InstanceCla
1200
1200
return [ ] ;
1201
1201
}
1202
1202
1203
- function validateSpotConfig ( id : string , spot ?: boolean , spotBidPercentage ?: number , spotFleetRole ?: iam . IRole ) : void {
1203
+ function validateSpotConfig ( scope : Construct , spot ?: boolean , spotBidPercentage ?: number , spotFleetRole ?: iam . IRole ) : void {
1204
1204
if ( spotBidPercentage ) {
1205
1205
if ( ! spot ) {
1206
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'spotBidPercentage' without specifying 'spot'` ) ;
1206
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'spotBidPercentage' without specifying 'spot'` , scope ) ;
1207
1207
}
1208
1208
1209
1209
if ( ! Token . isUnresolved ( spotBidPercentage ) ) {
1210
1210
if ( spotBidPercentage > 100 ) {
1211
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'spotBidPercentage' > 100` ) ;
1211
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'spotBidPercentage' > 100` , scope ) ;
1212
1212
} else if ( spotBidPercentage < 0 ) {
1213
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'spotBidPercentage' < 0` ) ;
1213
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'spotBidPercentage' < 0` , scope ) ;
1214
1214
}
1215
1215
}
1216
1216
}
1217
1217
1218
1218
if ( spotFleetRole ) {
1219
1219
if ( ! spot ) {
1220
- throw new Error ( `Managed ComputeEnvironment '${ id } ' specifies 'spotFleetRole' without specifying 'spot'` ) ;
1220
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' specifies 'spotFleetRole' without specifying 'spot'` , scope ) ;
1221
1221
}
1222
1222
}
1223
1223
}
1224
1224
1225
- function validateVCpus ( id : string , minvCpus : number , maxvCpus : number ) : void {
1225
+ function validateVCpus ( scope : Construct , minvCpus : number , maxvCpus : number ) : void {
1226
1226
if ( ! Token . isUnresolved ( minvCpus ) && minvCpus < 0 ) {
1227
- throw new Error ( `Managed ComputeEnvironment '${ id } ' has 'minvCpus' = ${ minvCpus } < 0; 'minvCpus' cannot be less than zero` ) ;
1227
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' has 'minvCpus' = ${ minvCpus } < 0; 'minvCpus' cannot be less than zero` , scope ) ;
1228
1228
}
1229
1229
if ( ! Token . isUnresolved ( minvCpus ) && ! Token . isUnresolved ( maxvCpus ) && minvCpus > maxvCpus ) {
1230
- throw new Error ( `Managed ComputeEnvironment '${ id } ' has 'minvCpus' = ${ minvCpus } > 'maxvCpus' = ${ maxvCpus } ; 'minvCpus' cannot be greater than 'maxvCpus'` ) ;
1230
+ throw new ValidationError ( `Managed ComputeEnvironment '${ scope . node . id } ' has 'minvCpus' = ${ minvCpus } > 'maxvCpus' = ${ maxvCpus } ; 'minvCpus' cannot be greater than 'maxvCpus'` , scope ) ;
1231
1231
}
1232
1232
}
1233
1233
0 commit comments