Skip to content

Commit

Permalink
chore(elasticloadbalancingv2): Add duration checks for slow start tar…
Browse files Browse the repository at this point in the history
…get group attribute (aws#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*
  • Loading branch information
robertd authored Feb 25, 2021
1 parent b7b441f commit 8712b40
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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.');
}
this.setAttribute('slow_start.duration_seconds', props.slowStart.toSeconds().toString());
}
if (props.stickinessCookieDuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,21 @@ describe('tests', () => {
});
}).toThrow(/Stickiness cookie duration value must be between 1 second and 7 days \(604800 seconds\)./);
});

test('Bad slow start duration value', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'VPC', {});

// THEN
[cdk.Duration.minutes(16), cdk.Duration.seconds(29)].forEach((badDuration, i) => {
expect(() => {
new elbv2.ApplicationTargetGroup(stack, `TargetGroup${i}`, {
slowStart: badDuration,
vpc,
});
}).toThrow(/Slow start duration value must be between 30 and 900 seconds./);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@
"Port": 80,
"Protocol": "HTTP",
"TargetGroupAttributes": [
{
"Key": "slow_start.duration_seconds",
"Value": "60"
},
{
"Key": "stickiness.enabled",
"Value": "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const group2 = listener.addTargets('ConditionalTarget', {
targets: [new elbv2.IpTarget('10.0.128.5')],
stickinessCookieDuration: cdk.Duration.minutes(5),
stickinessCookieName: 'MyDeliciousCookie',
slowStart: cdk.Duration.minutes(1),
});

group1.metricTargetResponseTime().createAlarm(stack, 'ResponseTimeHigh1', {
Expand Down

0 comments on commit 8712b40

Please sign in to comment.