Skip to content

Commit 8712b40

Browse files
authored
chore(elasticloadbalancingv2): Add duration checks for slow start target group attribute (#13265)
One more duration check... safety first :) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b7b441f commit 8712b40

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
123123

124124
if (props) {
125125
if (props.slowStart !== undefined) {
126+
if (props.slowStart.toSeconds() < 30 || props.slowStart.toSeconds() > 900) {
127+
throw new Error('Slow start duration value must be between 30 and 900 seconds.');
128+
}
126129
this.setAttribute('slow_start.duration_seconds', props.slowStart.toSeconds().toString());
127130
}
128131
if (props.stickinessCookieDuration) {

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

+17
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,21 @@ describe('tests', () => {
205205
});
206206
}).toThrow(/Stickiness cookie duration value must be between 1 second and 7 days \(604800 seconds\)./);
207207
});
208+
209+
test('Bad slow start duration value', () => {
210+
// GIVEN
211+
const app = new cdk.App();
212+
const stack = new cdk.Stack(app, 'Stack');
213+
const vpc = new ec2.Vpc(stack, 'VPC', {});
214+
215+
// THEN
216+
[cdk.Duration.minutes(16), cdk.Duration.seconds(29)].forEach((badDuration, i) => {
217+
expect(() => {
218+
new elbv2.ApplicationTargetGroup(stack, `TargetGroup${i}`, {
219+
slowStart: badDuration,
220+
vpc,
221+
});
222+
}).toThrow(/Slow start duration value must be between 30 and 900 seconds./);
223+
});
224+
});
208225
});

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.expected.json

+4
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@
469469
"Port": 80,
470470
"Protocol": "HTTP",
471471
"TargetGroupAttributes": [
472+
{
473+
"Key": "slow_start.duration_seconds",
474+
"Value": "60"
475+
},
472476
{
473477
"Key": "stickiness.enabled",
474478
"Value": "true"

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const group2 = listener.addTargets('ConditionalTarget', {
3232
targets: [new elbv2.IpTarget('10.0.128.5')],
3333
stickinessCookieDuration: cdk.Duration.minutes(5),
3434
stickinessCookieName: 'MyDeliciousCookie',
35+
slowStart: cdk.Duration.minutes(1),
3536
});
3637

3738
group1.metricTargetResponseTime().createAlarm(stack, 'ResponseTimeHigh1', {

0 commit comments

Comments
 (0)