Skip to content

Commit

Permalink
feat(elasticloadbalancingv2): add grpc code matcher for alb (aws#13948)
Browse files Browse the repository at this point in the history
With aws#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 aws#13947

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ChristopheBougere authored and hollanddd committed Aug 26, 2021
1 parent c92c8c4 commit 9193f99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ const tg = new elbv2.ApplicationTargetGroup(stack, 'TG', {
port: 50051,
protocol: elbv2.ApplicationProtocol.HTTP,
protocolVersion: elbv2.ApplicationProtocolVersion.GRPC,
healthCheck: {
enabled: true,
healthyGrpcCodes: '0-99',
},
vpc,
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ export interface HealthCheck {
*/
readonly unhealthyThresholdCount?: number;

/**
* GRPC code to use when checking for a successful response from a target.
*
* You can specify values between 0 and 99. You can specify multiple values
* (for example, "0,1") or a range of values (for example, "0-5").
*
* @default - 12
*/
readonly healthyGrpcCodes?: string;

/**
* HTTP code to use when checking for a successful response from a target.
*
Expand Down Expand Up @@ -259,7 +269,8 @@ export abstract class TargetGroupBase extends CoreConstruct implements ITargetGr
healthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.healthyThresholdCount }),
unhealthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.unhealthyThresholdCount }),
matcher: cdk.Lazy.any({
produce: () => this.healthCheck?.healthyHttpCodes !== undefined ? {
produce: () => this.healthCheck?.healthyHttpCodes !== undefined || this.healthCheck?.healthyGrpcCodes !== undefined ? {
grpcCode: this.healthCheck.healthyGrpcCodes,
httpCode: this.healthCheck.healthyHttpCodes,
} : undefined,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,29 @@ describe('tests', () => {
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
vpc,
protocolVersion: elbv2.ApplicationProtocolVersion.GRPC,
healthCheck: {
enabled: true,
healthyGrpcCodes: '0-99',
interval: cdk.Duration.seconds(255),
timeout: cdk.Duration.seconds(192),
healthyThresholdCount: 29,
unhealthyThresholdCount: 27,
path: '/arbitrary',
},
});

// THEN
expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', {
ProtocolVersion: 'GRPC',
HealthCheckEnabled: true,
HealthCheckIntervalSeconds: 255,
HealthCheckPath: '/arbitrary',
HealthCheckTimeoutSeconds: 192,
HealthyThresholdCount: 29,
Matcher: {
GrpcCode: '0-99',
},
UnhealthyThresholdCount: 27,
});
});

Expand Down

0 comments on commit 9193f99

Please sign in to comment.