Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elasticloadbalancingv2): allow alb slow start duration of 0 seconds #29445

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we need to handle where slowStart is not specified/undefined, to explicity set slow_start.duration_seconds attribute as default 0. since I saw in the issue reported, it was mentioned if it is not specified, it deploys successfully but Target Group resource still has it enabled(if previously enabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. I think if they want it disabled they should have to set it explicitly ? My concern is if we set to 0, it will cause changes with stacks that are already deployed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah seems valid. This looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!

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
Loading