Skip to content

Commit

Permalink
fix(globalaccelerator-endpoints): add preserveClientIp option for net… (
Browse files Browse the repository at this point in the history
aws#30346)

…work loadbalancer

### Issue # (if applicable)

### Reason for this change

preserveClientIp was missing for GlobalAccelerator Endpoints when using a network loadbalancer.

### Description of changes

* add missing network load balancer endpoint prop.

### Description of how you validated changes

Added unit tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
  • Loading branch information
SaschaJanssen authored and mazyu36 committed Jun 22, 2024
1 parent b97af8e commit 5865d0b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,18 @@
}
},
{
"ClientIPPreservationEnabled": true,
"EndpointId": {
"Ref": "ALBAEE750D2"
}
},
{
"EndpointId": {
"Ref": "NLB55158F82"
}
},
{
"ClientIPPreservationEnabled": true,
"EndpointId": {
"Ref": "NLB55158F82"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class GaStack extends Stack {
listener,
endpoints: [
new endpoints.ApplicationLoadBalancerEndpoint(alb),
new endpoints.ApplicationLoadBalancerEndpoint(alb, { preserveClientIp: true }),
new endpoints.NetworkLoadBalancerEndpoint(nlb),
new endpoints.NetworkLoadBalancerEndpoint(nlb, { preserveClientIp: true }),
new endpoints.CfnEipEndpoint(eip),
new endpoints.InstanceEndpoint(instances[0]),
new endpoints.InstanceEndpoint(instances[1]),
Expand Down
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/nlb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ export interface NetworkLoadBalancerEndpointProps {
* @default 128
*/
readonly weight?: number;

/**
* Forward the client IP address in an `X-Forwarded-For` header
*
* GlobalAccelerator will create Network Interfaces in your VPC in order
* to preserve the client IP address.
*
* Client IP address preservation is supported only in specific AWS Regions.
* See the GlobalAccelerator Developer Guide for a list.
*
* @default false
*/
readonly preserveClientIp?: boolean;
}

/**
Expand All @@ -31,6 +44,7 @@ export class NetworkLoadBalancerEndpoint implements ga.IEndpoint {
return {
endpointId: this.loadBalancer.loadBalancerArn,
weight: this.options.weight,
clientIpPreservationEnabled: this.options.preserveClientIp,
} as ga.CfnEndpointGroup.EndpointConfigurationProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ test('Network Load Balancer with all properties', () => {
endpoints: [
new endpoints.NetworkLoadBalancerEndpoint(nlb, {
weight: 50,
preserveClientIp: true,
}),
],
});
Expand All @@ -84,6 +85,7 @@ test('Network Load Balancer with all properties', () => {
{
EndpointId: { Ref: 'NLB55158F82' },
Weight: 50,
ClientIPPreservationEnabled: true,
},
],
});
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-globalaccelerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ listener.addEndpointGroup('Group', {
endpoints: [
new ga_endpoints.NetworkLoadBalancerEndpoint(nlb, {
weight: 128,
preserveClientIp: true,
}),
],
});
Expand Down

0 comments on commit 5865d0b

Please sign in to comment.