Skip to content

Commit

Permalink
fix(globalaccelerator-endpoints): add preserveClientIp option for net…
Browse files Browse the repository at this point in the history
…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 integration 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)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Sascha committed May 27, 2024
1 parent c073617 commit f4a4607
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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 true if available
*/
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 f4a4607

Please sign in to comment.