Skip to content

Commit 4f83e02

Browse files
fix(elbv2): healthcheck interval is overly restrictive (#24157)
The health check interval of network target groups can only be set to 10 or 30 seconds. [The allowed range is 5-300 ](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-health-checks.html) Closes #24156 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6c935c7 commit 4f83e02

12 files changed

+92
-46
lines changed

packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,12 @@ export class NetworkTargetGroup extends TargetGroupBase implements INetworkTarge
236236

237237
const healthCheck: HealthCheck = this.healthCheck || {};
238238

239-
const allowedIntervals = [10, 30];
239+
const lowHealthCheckInterval = 5;
240+
const highHealthCheckInterval = 300;
240241
if (healthCheck.interval) {
241242
const seconds = healthCheck.interval.toSeconds();
242-
if (!cdk.Token.isUnresolved(seconds) && !allowedIntervals.includes(seconds)) {
243-
ret.push(`Health check interval '${seconds}' not supported. Must be one of the following values '${allowedIntervals.join(',')}'.`);
243+
if (!cdk.Token.isUnresolved(seconds) && (seconds < lowHealthCheckInterval || seconds > highHealthCheckInterval)) {
244+
ret.push(`Health check interval '${seconds}' not supported. Must be between ${lowHealthCheckInterval} and ${highHealthCheckInterval}.`);
244245
}
245246
}
246247

packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ export interface HealthCheck {
7474

7575
/**
7676
* The approximate number of seconds between health checks for an individual target.
77+
* Must be 5 to 300 seconds
7778
*
78-
* @default Duration.seconds(30)
79+
* @default 10 seconds if protocol is `GENEVE`, 35 seconds if target type is `lambda`, else 30 seconds
7980
*/
8081
readonly interval?: cdk.Duration;
8182

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.nlb.js.snapshot/aws-cdk-elbv2-integ.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.0.0",
33
"files": {
4-
"4ac709cf496678c5d2ee9fb122c995688f00a12297a81f2ecf125722d79e9bf4": {
4+
"c7b59451188880618122593d9b5f98c0e30ff60bb10bb205c4c1a053fcdc4e79": {
55
"source": {
66
"path": "aws-cdk-elbv2-integ.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "4ac709cf496678c5d2ee9fb122c995688f00a12297a81f2ecf125722d79e9bf4.json",
12+
"objectKey": "c7b59451188880618122593d9b5f98c0e30ff60bb10bb205c4c1a053fcdc4e79.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.nlb.js.snapshot/aws-cdk-elbv2-integ.template.json

+2
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@
439439
"LBListenerTargetGroupF04FCF6D": {
440440
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
441441
"Properties": {
442+
"HealthCheckIntervalSeconds": 250,
443+
"HealthCheckProtocol": "TCP",
442444
"Port": 443,
443445
"Protocol": "TCP",
444446
"Targets": [
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"30.0.0"}

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.nlb.js.snapshot/elbv2integDefaultTestDeployAssert6120E394.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.0.0",
33
"testCases": {
44
"elbv2-integ/DefaultTest": {
55
"stacks": [
66
"aws-cdk-elbv2-integ"
77
],
8-
"assertionStack": "elbv2-integ/DefaultTest/DeployAssert"
8+
"assertionStack": "elbv2-integ/DefaultTest/DeployAssert",
9+
"assertionStackName": "elbv2integDefaultTestDeployAssert6120E394"
910
}
1011
}
1112
}

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.nlb.js.snapshot/manifest.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"aws-cdk-elbv2-integ.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -23,7 +17,7 @@
2317
"validateOnSynth": false,
2418
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2519
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4ac709cf496678c5d2ee9fb122c995688f00a12297a81f2ecf125722d79e9bf4.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c7b59451188880618122593d9b5f98c0e30ff60bb10bb205c4c1a053fcdc4e79.json",
2721
"requiresBootstrapStackVersion": 6,
2822
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2923
"additionalDependencies": [
@@ -256,6 +250,12 @@
256250
]
257251
},
258252
"displayName": "elbv2-integ/DefaultTest/DeployAssert"
253+
},
254+
"Tree": {
255+
"type": "cdk:tree",
256+
"properties": {
257+
"file": "tree.json"
258+
}
259259
}
260260
}
261261
}

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.nlb.js.snapshot/tree.json

+59-23
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
"id": "App",
55
"path": "",
66
"children": {
7-
"Tree": {
8-
"id": "Tree",
9-
"path": "Tree",
10-
"constructInfo": {
11-
"fqn": "constructs.Construct",
12-
"version": "10.1.85"
13-
}
14-
},
157
"aws-cdk-elbv2-integ": {
168
"id": "aws-cdk-elbv2-integ",
179
"path": "aws-cdk-elbv2-integ",
@@ -91,8 +83,8 @@
9183
"id": "Acl",
9284
"path": "aws-cdk-elbv2-integ/VPC/PublicSubnet1/Acl",
9385
"constructInfo": {
94-
"fqn": "constructs.Construct",
95-
"version": "10.1.85"
86+
"fqn": "@aws-cdk/core.Resource",
87+
"version": "0.0.0"
9688
}
9789
},
9890
"RouteTable": {
@@ -258,8 +250,8 @@
258250
"id": "Acl",
259251
"path": "aws-cdk-elbv2-integ/VPC/PublicSubnet2/Acl",
260252
"constructInfo": {
261-
"fqn": "constructs.Construct",
262-
"version": "10.1.85"
253+
"fqn": "@aws-cdk/core.Resource",
254+
"version": "0.0.0"
263255
}
264256
},
265257
"RouteTable": {
@@ -425,8 +417,8 @@
425417
"id": "Acl",
426418
"path": "aws-cdk-elbv2-integ/VPC/PrivateSubnet1/Acl",
427419
"constructInfo": {
428-
"fqn": "constructs.Construct",
429-
"version": "10.1.85"
420+
"fqn": "@aws-cdk/core.Resource",
421+
"version": "0.0.0"
430422
}
431423
},
432424
"RouteTable": {
@@ -544,8 +536,8 @@
544536
"id": "Acl",
545537
"path": "aws-cdk-elbv2-integ/VPC/PrivateSubnet2/Acl",
546538
"constructInfo": {
547-
"fqn": "constructs.Construct",
548-
"version": "10.1.85"
539+
"fqn": "@aws-cdk/core.Resource",
540+
"version": "0.0.0"
549541
}
550542
},
551543
"RouteTable": {
@@ -732,6 +724,8 @@
732724
"attributes": {
733725
"aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::TargetGroup",
734726
"aws:cdk:cloudformation:props": {
727+
"healthCheckIntervalSeconds": 250,
728+
"healthCheckProtocol": "TCP",
735729
"port": 443,
736730
"protocol": "TCP",
737731
"targets": [
@@ -767,11 +761,27 @@
767761
"fqn": "@aws-cdk/aws-elasticloadbalancingv2.NetworkLoadBalancer",
768762
"version": "0.0.0"
769763
}
764+
},
765+
"BootstrapVersion": {
766+
"id": "BootstrapVersion",
767+
"path": "aws-cdk-elbv2-integ/BootstrapVersion",
768+
"constructInfo": {
769+
"fqn": "@aws-cdk/core.CfnParameter",
770+
"version": "0.0.0"
771+
}
772+
},
773+
"CheckBootstrapVersion": {
774+
"id": "CheckBootstrapVersion",
775+
"path": "aws-cdk-elbv2-integ/CheckBootstrapVersion",
776+
"constructInfo": {
777+
"fqn": "@aws-cdk/core.CfnRule",
778+
"version": "0.0.0"
779+
}
770780
}
771781
},
772782
"constructInfo": {
773-
"fqn": "constructs.Construct",
774-
"version": "10.1.85"
783+
"fqn": "@aws-cdk/core.Stack",
784+
"version": "0.0.0"
775785
}
776786
},
777787
"elbv2-integ": {
@@ -787,15 +797,33 @@
787797
"path": "elbv2-integ/DefaultTest/Default",
788798
"constructInfo": {
789799
"fqn": "constructs.Construct",
790-
"version": "10.1.85"
800+
"version": "10.1.249"
791801
}
792802
},
793803
"DeployAssert": {
794804
"id": "DeployAssert",
795805
"path": "elbv2-integ/DefaultTest/DeployAssert",
806+
"children": {
807+
"BootstrapVersion": {
808+
"id": "BootstrapVersion",
809+
"path": "elbv2-integ/DefaultTest/DeployAssert/BootstrapVersion",
810+
"constructInfo": {
811+
"fqn": "@aws-cdk/core.CfnParameter",
812+
"version": "0.0.0"
813+
}
814+
},
815+
"CheckBootstrapVersion": {
816+
"id": "CheckBootstrapVersion",
817+
"path": "elbv2-integ/DefaultTest/DeployAssert/CheckBootstrapVersion",
818+
"constructInfo": {
819+
"fqn": "@aws-cdk/core.CfnRule",
820+
"version": "0.0.0"
821+
}
822+
}
823+
},
796824
"constructInfo": {
797-
"fqn": "constructs.Construct",
798-
"version": "10.1.85"
825+
"fqn": "@aws-cdk/core.Stack",
826+
"version": "0.0.0"
799827
}
800828
}
801829
},
@@ -809,11 +837,19 @@
809837
"fqn": "@aws-cdk/integ-tests.IntegTest",
810838
"version": "0.0.0"
811839
}
840+
},
841+
"Tree": {
842+
"id": "Tree",
843+
"path": "Tree",
844+
"constructInfo": {
845+
"fqn": "constructs.Construct",
846+
"version": "10.1.249"
847+
}
812848
}
813849
},
814850
"constructInfo": {
815-
"fqn": "constructs.Construct",
816-
"version": "10.1.85"
851+
"fqn": "@aws-cdk/core.App",
852+
"version": "0.0.0"
817853
}
818854
}
819855
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const group = listener.addTargets('Target', {
2424
targets: [new elbv2.IpTarget('10.0.1.1')],
2525
});
2626

27+
group.configureHealthCheck({
28+
interval: cdk.Duration.seconds(250),
29+
protocol: elbv2.Protocol.TCP,
30+
});
31+
2732
vpc.publicSubnets.forEach(subnet => group.node.addDependency(subnet));
2833
group.node.addDependency(vpc.internetConnectivityEstablished);
2934

packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/listener.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ describe('tests', () => {
307307
const targetGroup = listener.addTargets('ECS', {
308308
port: 80,
309309
healthCheck: {
310-
interval: cdk.Duration.seconds(60),
310+
interval: cdk.Duration.seconds(350),
311311
},
312312
});
313313

314314
const validationErrors: string[] = targetGroup.node.validate();
315-
const intervalError = validationErrors.find((err) => /Health check interval '60' not supported. Must be one of the following values/.test(err));
315+
const intervalError = validationErrors.find((err) => /Health check interval '350' not supported. Must be between/.test(err));
316316
expect(intervalError).toBeDefined();
317317
});
318318

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ describe('tests', () => {
135135
vpc,
136136
port: 80,
137137
healthCheck: {
138-
interval: cdk.Duration.seconds(5),
138+
interval: cdk.Duration.seconds(3),
139139
},
140140
});
141141

142142
expect(() => {
143143
app.synth();
144-
}).toThrow(/Health check interval '5' not supported. Must be one of the following values '10,30'./);
144+
}).toThrow(/Health check interval '3' not supported. Must be between 5 and 300./);
145145
});
146146

147147
test('targetGroupName unallowed: more than 32 characters', () => {

0 commit comments

Comments
 (0)