@@ -14,8 +14,7 @@ import {
14
14
import { IRole } from '../../../aws-iam' ;
15
15
import { ARecord , IHostedZone , RecordTarget , CnameRecord } from '../../../aws-route53' ;
16
16
import { LoadBalancerTarget } from '../../../aws-route53-targets' ;
17
- import * as cdk from '../../../core' ;
18
- import { Duration } from '../../../core' ;
17
+ import { CfnOutput , Duration , Stack , Token , ValidationError } from '../../../core' ;
19
18
20
19
/**
21
20
* Describes the type of DNS record the service should create
@@ -150,7 +149,7 @@ export interface ApplicationLoadBalancedServiceBaseProps {
150
149
*
151
150
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
152
151
*/
153
- readonly healthCheckGracePeriod ?: cdk . Duration ;
152
+ readonly healthCheckGracePeriod ?: Duration ;
154
153
155
154
/**
156
155
* The maximum number of tasks, specified as a percentage of the Amazon ECS
@@ -423,7 +422,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
423
422
*/
424
423
public get loadBalancer ( ) : ApplicationLoadBalancer {
425
424
if ( ! this . _applicationLoadBalancer ) {
426
- throw new Error ( '.loadBalancer can only be accessed if the class was constructed with an owned, not imported, load balancer' ) ;
425
+ throw new ValidationError ( '.loadBalancer can only be accessed if the class was constructed with an owned, not imported, load balancer' , this ) ;
427
426
}
428
427
return this . _applicationLoadBalancer ;
429
428
}
@@ -462,12 +461,12 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
462
461
super ( scope , id ) ;
463
462
464
463
if ( props . cluster && props . vpc ) {
465
- throw new Error ( 'You can only specify either vpc or cluster. Alternatively, you can leave both blank' ) ;
464
+ throw new ValidationError ( 'You can only specify either vpc or cluster. Alternatively, you can leave both blank' , this ) ;
466
465
}
467
466
this . cluster = props . cluster || this . getDefaultCluster ( this , props . vpc ) ;
468
467
469
- if ( props . desiredCount !== undefined && ! cdk . Token . isUnresolved ( props . desiredCount ) && props . desiredCount < 1 ) {
470
- throw new Error ( 'You must specify a desiredCount greater than 0' ) ;
468
+ if ( props . desiredCount !== undefined && ! Token . isUnresolved ( props . desiredCount ) && props . desiredCount < 1 ) {
469
+ throw new ValidationError ( 'You must specify a desiredCount greater than 0' , this ) ;
471
470
}
472
471
473
472
this . desiredCount = props . desiredCount || 1 ;
@@ -478,7 +477,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
478
477
if ( props . idleTimeout ) {
479
478
const idleTimeout = props . idleTimeout . toSeconds ( ) ;
480
479
if ( idleTimeout > Duration . seconds ( 4000 ) . toSeconds ( ) || idleTimeout < Duration . seconds ( 1 ) . toSeconds ( ) ) {
481
- throw new Error ( 'Load balancer idle timeout must be between 1 and 4000 seconds.' ) ;
480
+ throw new ValidationError ( 'Load balancer idle timeout must be between 1 and 4000 seconds.' , this ) ;
482
481
}
483
482
}
484
483
@@ -493,12 +492,12 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
493
492
const loadBalancer = props . loadBalancer ?? new ApplicationLoadBalancer ( this , 'LB' , lbProps ) ;
494
493
495
494
if ( props . certificate !== undefined && props . protocol !== undefined && props . protocol !== ApplicationProtocol . HTTPS ) {
496
- throw new Error ( 'The HTTPS protocol must be used when a certificate is given' ) ;
495
+ throw new ValidationError ( 'The HTTPS protocol must be used when a certificate is given' , this ) ;
497
496
}
498
497
const protocol = props . protocol ?? ( props . certificate ? ApplicationProtocol . HTTPS : ApplicationProtocol . HTTP ) ;
499
498
500
499
if ( protocol !== ApplicationProtocol . HTTPS && props . redirectHTTP === true ) {
501
- throw new Error ( 'The HTTPS protocol must be used when redirecting HTTP traffic' ) ;
500
+ throw new ValidationError ( 'The HTTPS protocol must be used when redirecting HTTP traffic' , this ) ;
502
501
}
503
502
504
503
const targetProps : AddApplicationTargetsProps = {
@@ -519,7 +518,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
519
518
this . certificate = props . certificate ;
520
519
} else {
521
520
if ( typeof props . domainName === 'undefined' || typeof props . domainZone === 'undefined' ) {
522
- throw new Error ( 'A domain name and zone is required when using the HTTPS protocol' ) ;
521
+ throw new ValidationError ( 'A domain name and zone is required when using the HTTPS protocol' , this ) ;
523
522
}
524
523
525
524
this . certificate = new Certificate ( this , 'Certificate' , {
@@ -547,7 +546,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
547
546
let domainName = loadBalancer . loadBalancerDnsName ;
548
547
if ( typeof props . domainName !== 'undefined' ) {
549
548
if ( typeof props . domainZone === 'undefined' ) {
550
- throw new Error ( 'A Route53 hosted domain zone name is required to configure the specified domain name' ) ;
549
+ throw new ValidationError ( 'A Route53 hosted domain zone name is required to configure the specified domain name' , this ) ;
551
550
}
552
551
553
552
switch ( props . recordType ?? ApplicationLoadBalancedServiceRecordType . ALIAS ) {
@@ -577,8 +576,8 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
577
576
this . _applicationLoadBalancer = loadBalancer ;
578
577
}
579
578
580
- new cdk . CfnOutput ( this , 'LoadBalancerDNS' , { value : loadBalancer . loadBalancerDnsName } ) ;
581
- new cdk . CfnOutput ( this , 'ServiceURL' , { value : protocol . toLowerCase ( ) + '://' + domainName } ) ;
579
+ new CfnOutput ( this , 'LoadBalancerDNS' , { value : loadBalancer . loadBalancerDnsName } ) ;
580
+ new CfnOutput ( this , 'ServiceURL' , { value : protocol . toLowerCase ( ) + '://' + domainName } ) ;
582
581
}
583
582
584
583
/**
@@ -587,7 +586,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends Construct {
587
586
protected getDefaultCluster ( scope : Construct , vpc ?: IVpc ) : Cluster {
588
587
// magic string to avoid collision with user-defined constructs
589
588
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${ vpc ? vpc . node . id : '' } ` ;
590
- const stack = cdk . Stack . of ( scope ) ;
589
+ const stack = Stack . of ( scope ) ;
591
590
return stack . node . tryFindChild ( DEFAULT_CLUSTER_ID ) as Cluster || new Cluster ( stack , DEFAULT_CLUSTER_ID , { vpc } ) ;
592
591
}
593
592
0 commit comments