@@ -28,13 +28,15 @@ export interface AutoScalingGroupProps {
28
28
29
29
/**
30
30
* Minimum number of instances in the fleet
31
+ *
31
32
* @default 1
32
33
*/
33
34
minSize ?: number ;
34
35
35
36
/**
36
37
* Maximum number of instances in the fleet
37
- * @default 1
38
+ *
39
+ * @default desiredCapacity
38
40
*/
39
41
maxSize ?: number ;
40
42
@@ -234,9 +236,12 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
234
236
235
237
launchConfig . addDependency ( this . role ) ;
236
238
239
+ const desiredCapacity =
240
+ ( props . desiredCapacity !== undefined ? props . desiredCapacity :
241
+ ( props . minSize !== undefined ? props . minSize :
242
+ ( props . maxSize !== undefined ? props . maxSize : 1 ) ) ) ;
237
243
const minSize = props . minSize !== undefined ? props . minSize : 1 ;
238
- const maxSize = props . maxSize !== undefined ? props . maxSize : 1 ;
239
- const desiredCapacity = props . desiredCapacity !== undefined ? props . desiredCapacity : 1 ;
244
+ const maxSize = props . maxSize !== undefined ? props . maxSize : desiredCapacity ;
240
245
241
246
if ( desiredCapacity < minSize || desiredCapacity > maxSize ) {
242
247
throw new Error ( `Should have minSize (${ minSize } ) <= desiredCapacity (${ desiredCapacity } ) <= maxSize (${ maxSize } )` ) ;
@@ -322,8 +327,8 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
322
327
/**
323
328
* Scale out or in based on time
324
329
*/
325
- public scaleOnSchedule ( id : string , props : BasicScheduledActionProps ) {
326
- new ScheduledAction ( this , `ScheduledAction${ id } ` , {
330
+ public scaleOnSchedule ( id : string , props : BasicScheduledActionProps ) : ScheduledAction {
331
+ return new ScheduledAction ( this , `ScheduledAction${ id } ` , {
327
332
autoScalingGroup : this ,
328
333
...props ,
329
334
} ) ;
@@ -332,7 +337,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
332
337
/**
333
338
* Scale out or in to achieve a target CPU utilization
334
339
*/
335
- public scaleOnCpuUtilization ( id : string , props : CpuUtilizationScalingProps ) {
340
+ public scaleOnCpuUtilization ( id : string , props : CpuUtilizationScalingProps ) : TargetTrackingScalingPolicy {
336
341
return new TargetTrackingScalingPolicy ( this , `ScalingPolicy${ id } ` , {
337
342
autoScalingGroup : this ,
338
343
predefinedMetric : PredefinedMetric . ASGAverageCPUUtilization ,
@@ -344,7 +349,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
344
349
/**
345
350
* Scale out or in to achieve a target network ingress rate
346
351
*/
347
- public scaleOnIncomingBytes ( id : string , props : NetworkUtilizationScalingProps ) {
352
+ public scaleOnIncomingBytes ( id : string , props : NetworkUtilizationScalingProps ) : TargetTrackingScalingPolicy {
348
353
return new TargetTrackingScalingPolicy ( this , `ScalingPolicy${ id } ` , {
349
354
autoScalingGroup : this ,
350
355
predefinedMetric : PredefinedMetric . ASGAverageNetworkIn ,
@@ -356,7 +361,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
356
361
/**
357
362
* Scale out or in to achieve a target network egress rate
358
363
*/
359
- public scaleOnOutgoingBytes ( id : string , props : NetworkUtilizationScalingProps ) {
364
+ public scaleOnOutgoingBytes ( id : string , props : NetworkUtilizationScalingProps ) : TargetTrackingScalingPolicy {
360
365
return new TargetTrackingScalingPolicy ( this , `ScalingPolicy${ id } ` , {
361
366
autoScalingGroup : this ,
362
367
predefinedMetric : PredefinedMetric . ASGAverageNetworkOut ,
@@ -371,7 +376,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
371
376
* The AutoScalingGroup must have been attached to an Application Load Balancer
372
377
* in order to be able to call this.
373
378
*/
374
- public scaleOnRequestCount ( id : string , props : RequestCountScalingProps ) {
379
+ public scaleOnRequestCount ( id : string , props : RequestCountScalingProps ) : TargetTrackingScalingPolicy {
375
380
if ( this . albTargetGroup === undefined ) {
376
381
throw new Error ( 'Attach the AutoScalingGroup to an Application Load Balancer before calling scaleOnRequestCount()' ) ;
377
382
}
@@ -389,13 +394,14 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
389
394
// Target tracking policy can only be created after the load balancer has been
390
395
// attached to the targetgroup (because we need its ARN).
391
396
policy . addDependency ( this . albTargetGroup . loadBalancerDependency ( ) ) ;
397
+ return policy ;
392
398
}
393
399
394
400
/**
395
401
* Scale out or in in order to keep a metric around a target value
396
402
*/
397
- public scaleToTrackMetric ( id : string , props : MetricTargetTrackingProps ) {
398
- new TargetTrackingScalingPolicy ( this , `ScalingPolicy${ id } ` , {
403
+ public scaleToTrackMetric ( id : string , props : MetricTargetTrackingProps ) : TargetTrackingScalingPolicy {
404
+ return new TargetTrackingScalingPolicy ( this , `ScalingPolicy${ id } ` , {
399
405
autoScalingGroup : this ,
400
406
customMetric : props . metric ,
401
407
...props
@@ -405,7 +411,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
405
411
/**
406
412
* Scale out or in, in response to a metric
407
413
*/
408
- public scaleOnMetric ( id : string , props : BasicStepScalingPolicyProps ) {
414
+ public scaleOnMetric ( id : string , props : BasicStepScalingPolicyProps ) : StepScalingPolicy {
409
415
return new StepScalingPolicy ( this , id , { ...props , autoScalingGroup : this } ) ;
410
416
}
411
417
@@ -658,6 +664,41 @@ export interface IAutoScalingGroup {
658
664
* The name of the AutoScalingGroup
659
665
*/
660
666
readonly autoScalingGroupName : string ;
667
+
668
+ /**
669
+ * Send a message to either an SQS queue or SNS topic when instances launch or terminate
670
+ */
671
+ onLifecycleTransition ( id : string , props : BasicLifecycleHookProps ) : LifecycleHook ;
672
+
673
+ /**
674
+ * Scale out or in based on time
675
+ */
676
+ scaleOnSchedule ( id : string , props : BasicScheduledActionProps ) : ScheduledAction ;
677
+
678
+ /**
679
+ * Scale out or in to achieve a target CPU utilization
680
+ */
681
+ scaleOnCpuUtilization ( id : string , props : CpuUtilizationScalingProps ) : TargetTrackingScalingPolicy ;
682
+
683
+ /**
684
+ * Scale out or in to achieve a target network ingress rate
685
+ */
686
+ scaleOnIncomingBytes ( id : string , props : NetworkUtilizationScalingProps ) : TargetTrackingScalingPolicy ;
687
+
688
+ /**
689
+ * Scale out or in to achieve a target network egress rate
690
+ */
691
+ scaleOnOutgoingBytes ( id : string , props : NetworkUtilizationScalingProps ) : TargetTrackingScalingPolicy ;
692
+
693
+ /**
694
+ * Scale out or in in order to keep a metric around a target value
695
+ */
696
+ scaleToTrackMetric ( id : string , props : MetricTargetTrackingProps ) : TargetTrackingScalingPolicy ;
697
+
698
+ /**
699
+ * Scale out or in, in response to a metric
700
+ */
701
+ scaleOnMetric ( id : string , props : BasicStepScalingPolicyProps ) : StepScalingPolicy ;
661
702
}
662
703
663
704
/**
0 commit comments