Skip to content

Commit c1e1b4d

Browse files
authoredJun 18, 2024··
fix(globalaccelerator-endpoints): add preserveClientIp option for net… (#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)
1 parent 798785c commit c1e1b4d

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed
 

‎packages/@aws-cdk-testing/framework-integ/test/aws-globalaccelerator-endpoints/test/integ.globalaccelerator.js.snapshot/integ-globalaccelerator.template.json

+12
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@
691691
}
692692
},
693693
{
694+
"ClientIPPreservationEnabled": true,
695+
"EndpointId": {
696+
"Ref": "ALBAEE750D2"
697+
}
698+
},
699+
{
700+
"EndpointId": {
701+
"Ref": "NLB55158F82"
702+
}
703+
},
704+
{
705+
"ClientIPPreservationEnabled": true,
694706
"EndpointId": {
695707
"Ref": "NLB55158F82"
696708
}

‎packages/@aws-cdk-testing/framework-integ/test/aws-globalaccelerator-endpoints/test/integ.globalaccelerator.ts

+2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class GaStack extends Stack {
3838
listener,
3939
endpoints: [
4040
new endpoints.ApplicationLoadBalancerEndpoint(alb),
41+
new endpoints.ApplicationLoadBalancerEndpoint(alb, { preserveClientIp: true }),
4142
new endpoints.NetworkLoadBalancerEndpoint(nlb),
43+
new endpoints.NetworkLoadBalancerEndpoint(nlb, { preserveClientIp: true }),
4244
new endpoints.CfnEipEndpoint(eip),
4345
new endpoints.InstanceEndpoint(instances[0]),
4446
new endpoints.InstanceEndpoint(instances[1]),

‎packages/aws-cdk-lib/aws-globalaccelerator-endpoints/lib/nlb.ts

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ export interface NetworkLoadBalancerEndpointProps {
1414
* @default 128
1515
*/
1616
readonly weight?: number;
17+
18+
/**
19+
* Forward the client IP address in an `X-Forwarded-For` header
20+
*
21+
* GlobalAccelerator will create Network Interfaces in your VPC in order
22+
* to preserve the client IP address.
23+
*
24+
* Client IP address preservation is supported only in specific AWS Regions.
25+
* See the GlobalAccelerator Developer Guide for a list.
26+
*
27+
* @default false
28+
*/
29+
readonly preserveClientIp?: boolean;
1730
}
1831

1932
/**
@@ -31,6 +44,7 @@ export class NetworkLoadBalancerEndpoint implements ga.IEndpoint {
3144
return {
3245
endpointId: this.loadBalancer.loadBalancerArn,
3346
weight: this.options.weight,
47+
clientIpPreservationEnabled: this.options.preserveClientIp,
3448
} as ga.CfnEndpointGroup.EndpointConfigurationProperty;
3549
}
3650
}

‎packages/aws-cdk-lib/aws-globalaccelerator-endpoints/test/endpoints.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ test('Network Load Balancer with all properties', () => {
7474
endpoints: [
7575
new endpoints.NetworkLoadBalancerEndpoint(nlb, {
7676
weight: 50,
77+
preserveClientIp: true,
7778
}),
7879
],
7980
});
@@ -84,6 +85,7 @@ test('Network Load Balancer with all properties', () => {
8485
{
8586
EndpointId: { Ref: 'NLB55158F82' },
8687
Weight: 50,
88+
ClientIPPreservationEnabled: true,
8789
},
8890
],
8991
});

‎packages/aws-cdk-lib/aws-globalaccelerator/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ listener.addEndpointGroup('Group', {
116116
endpoints: [
117117
new ga_endpoints.NetworkLoadBalancerEndpoint(nlb, {
118118
weight: 128,
119+
preserveClientIp: true,
119120
}),
120121
],
121122
});

0 commit comments

Comments
 (0)
Please sign in to comment.