Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(globalaccelerator-endpoints): add preserveClientIp option for net… #30346

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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