Skip to content

Commit a37f178

Browse files
feat(elasticloadbalancingv2): add grpc code matcher for alb (#13948)
With #13570, it is now possible to set the protocol version for ALB target groups, and thus make it working for GRPC. However, it is not yet possible to define a GrpcCode for the matcher (see [CloudFormation doc](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-targetgroup-matcher.html)). I added a `healthyGrpcCodes` working the same way as `healthyHttpCodes`. closes #13947 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 036d869 commit a37f178

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

packages/@aws-cdk/aws-elasticloadbalancingv2/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ const tg = new elbv2.ApplicationTargetGroup(stack, 'TG', {
283283
port: 50051,
284284
protocol: elbv2.ApplicationProtocol.HTTP,
285285
protocolVersion: elbv2.ApplicationProtocolVersion.GRPC,
286+
healthCheck: {
287+
enabled: true,
288+
healthyGrpcCodes: '0-99',
289+
},
286290
vpc,
287291
});
288292
```

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ export interface HealthCheck {
136136
*/
137137
readonly unhealthyThresholdCount?: number;
138138

139+
/**
140+
* GRPC code to use when checking for a successful response from a target.
141+
*
142+
* You can specify values between 0 and 99. You can specify multiple values
143+
* (for example, "0,1") or a range of values (for example, "0-5").
144+
*
145+
* @default - 12
146+
*/
147+
readonly healthyGrpcCodes?: string;
148+
139149
/**
140150
* HTTP code to use when checking for a successful response from a target.
141151
*
@@ -259,7 +269,8 @@ export abstract class TargetGroupBase extends CoreConstruct implements ITargetGr
259269
healthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.healthyThresholdCount }),
260270
unhealthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.unhealthyThresholdCount }),
261271
matcher: cdk.Lazy.any({
262-
produce: () => this.healthCheck?.healthyHttpCodes !== undefined ? {
272+
produce: () => this.healthCheck?.healthyHttpCodes !== undefined || this.healthCheck?.healthyGrpcCodes !== undefined ? {
273+
grpcCode: this.healthCheck.healthyGrpcCodes,
263274
httpCode: this.healthCheck.healthyHttpCodes,
264275
} : undefined,
265276
}),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,29 @@ describe('tests', () => {
166166
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
167167
vpc,
168168
protocolVersion: elbv2.ApplicationProtocolVersion.GRPC,
169+
healthCheck: {
170+
enabled: true,
171+
healthyGrpcCodes: '0-99',
172+
interval: cdk.Duration.seconds(255),
173+
timeout: cdk.Duration.seconds(192),
174+
healthyThresholdCount: 29,
175+
unhealthyThresholdCount: 27,
176+
path: '/arbitrary',
177+
},
169178
});
170179

171180
// THEN
172181
expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', {
173182
ProtocolVersion: 'GRPC',
183+
HealthCheckEnabled: true,
184+
HealthCheckIntervalSeconds: 255,
185+
HealthCheckPath: '/arbitrary',
186+
HealthCheckTimeoutSeconds: 192,
187+
HealthyThresholdCount: 29,
188+
Matcher: {
189+
GrpcCode: '0-99',
190+
},
191+
UnhealthyThresholdCount: 27,
174192
});
175193
});
176194

0 commit comments

Comments
 (0)