Skip to content

Commit cf2351b

Browse files
authored
fix(elasticloadbalancingv2): allow alb slow start duration of 0 seconds (#29445)
Closes #29437. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 28c4be3 commit cf2351b

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ const tg2 = new elbv2.ApplicationTargetGroup(this, 'TG2', {
335335
});
336336
```
337337

338+
### Slow start mode for your Application Load Balancer
339+
340+
By default, a target starts to receive its full share of requests as soon as it is registered with a target group and passes an initial health check. Using slow start mode gives targets time to warm up before the load balancer sends them a full share of requests.
341+
342+
After you enable slow start for a target group, its targets enter slow start mode when they are considered healthy by the target group. A target in slow start mode exits slow start mode when the configured slow start duration period elapses or the target becomes unhealthy. The load balancer linearly increases the number of requests that it can send to a target in slow start mode. After a healthy target exits slow start mode, the load balancer can send it a full share of requests.
343+
344+
The allowed range is 30-900 seconds (15 minutes). The default is 0 seconds (disabled).
345+
346+
```ts
347+
declare const vpc: ec2.Vpc;
348+
349+
// Target group with slow start mode enabled
350+
const tg = new elbv2.ApplicationTargetGroup(this, 'TG', {
351+
targetType: elbv2.TargetType.INSTANCE,
352+
slowStart: Duration.seconds(60),
353+
port: 80,
354+
vpc,
355+
});
356+
```
357+
338358
For more information see: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html#application-based-stickiness
339359

340360
### Setting the target group protocol version

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
330330

331331
if (props) {
332332
if (props.slowStart !== undefined) {
333-
if (props.slowStart.toSeconds() < 30 || props.slowStart.toSeconds() > 900) {
334-
throw new Error('Slow start duration value must be between 30 and 900 seconds.');
333+
// 0 is allowed and disables slow start
334+
if ((props.slowStart.toSeconds() < 30 && props.slowStart.toSeconds() !== 0) || props.slowStart.toSeconds() > 900) {
335+
throw new Error('Slow start duration value must be between 30 and 900 seconds, or 0 to disable slow start.');
335336
}
336337
this.setAttribute('slow_start.duration_seconds', props.slowStart.toSeconds().toString());
337338
}

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/target-group.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,33 @@ describe('tests', () => {
340340
slowStart: badDuration,
341341
vpc,
342342
});
343-
}).toThrow(/Slow start duration value must be between 30 and 900 seconds./);
343+
}).toThrow(/Slow start duration value must be between 30 and 900 seconds, or 0 to disable slow start./);
344+
});
345+
});
346+
347+
test('Disable slow start by setting to 0 seconds', () => {
348+
const app = new cdk.App();
349+
const stack = new cdk.Stack(app, 'Stack');
350+
const vpc = new ec2.Vpc(stack, 'VPC', {});
351+
352+
// WHEN
353+
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
354+
slowStart: cdk.Duration.seconds(0),
355+
vpc,
356+
});
357+
358+
// THEN
359+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
360+
TargetGroupAttributes: [
361+
{
362+
Key: 'slow_start.duration_seconds',
363+
Value: '0',
364+
},
365+
{
366+
Key: 'stickiness.enabled',
367+
Value: 'false',
368+
},
369+
],
344370
});
345371
});
346372

0 commit comments

Comments
 (0)