Skip to content

Commit

Permalink
Merge branch 'main' into 29523
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol authored Mar 18, 2024
2 parents e661f0a + cf2351b commit c4b2301
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,26 @@ const tg2 = new elbv2.ApplicationTargetGroup(this, 'TG2', {
});
```

### Slow start mode for your Application Load Balancer

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.

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.

The allowed range is 30-900 seconds (15 minutes). The default is 0 seconds (disabled).

```ts
declare const vpc: ec2.Vpc;

// Target group with slow start mode enabled
const tg = new elbv2.ApplicationTargetGroup(this, 'TG', {
targetType: elbv2.TargetType.INSTANCE,
slowStart: Duration.seconds(60),
port: 80,
vpc,
});
```

For more information see: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/sticky-sessions.html#application-based-stickiness

### Setting the target group protocol version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat

if (props) {
if (props.slowStart !== undefined) {
if (props.slowStart.toSeconds() < 30 || props.slowStart.toSeconds() > 900) {
throw new Error('Slow start duration value must be between 30 and 900 seconds.');
// 0 is allowed and disables slow start
if ((props.slowStart.toSeconds() < 30 && props.slowStart.toSeconds() !== 0) || props.slowStart.toSeconds() > 900) {
throw new Error('Slow start duration value must be between 30 and 900 seconds, or 0 to disable slow start.');
}
this.setAttribute('slow_start.duration_seconds', props.slowStart.toSeconds().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,33 @@ describe('tests', () => {
slowStart: badDuration,
vpc,
});
}).toThrow(/Slow start duration value must be between 30 and 900 seconds./);
}).toThrow(/Slow start duration value must be between 30 and 900 seconds, or 0 to disable slow start./);
});
});

test('Disable slow start by setting to 0 seconds', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC', {});

// WHEN
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
slowStart: cdk.Duration.seconds(0),
vpc,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
TargetGroupAttributes: [
{
Key: 'slow_start.duration_seconds',
Value: '0',
},
{
Key: 'stickiness.enabled',
Value: 'false',
},
],
});
});

Expand Down

0 comments on commit c4b2301

Please sign in to comment.