# ClientRoutingPolicy

Indicates how traffic is distributed among the load balancer Availability Zones.

- Source: [`aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts#L25)
- Type last changed: v2.134.0 · 26 Mar 2024

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;

const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
  vpc,
  // Whether deletion protection is enabled.
  deletionProtection: true,

  // Whether cross-zone load balancing is enabled.
  crossZoneEnabled: true,

  // Whether the load balancer blocks traffic through the Internet Gateway (IGW).
  denyAllIgwTraffic: false,

  // Indicates how traffic is distributed among the load balancer Availability Zones.
  clientRoutingPolicy: elbv2.ClientRoutingPolicy.AVAILABILITY_ZONE_AFFINITY,

  // Indicates whether zonal shift is enabled.
  zonalShift: true,
});
```

Python:

```python
# vpc: ec2.Vpc

lb = elbv2.NetworkLoadBalancer(self, "LB",
    vpc=vpc,
    # Whether deletion protection is enabled.
    deletion_protection=True,

    # Whether cross-zone load balancing is enabled.
    cross_zone_enabled=True,

    # Whether the load balancer blocks traffic through the Internet Gateway (IGW).
    deny_all_igw_traffic=False,

    # Indicates how traffic is distributed among the load balancer Availability Zones.
    client_routing_policy=elbv2.ClientRoutingPolicy.AVAILABILITY_ZONE_AFFINITY,

    # Indicates whether zonal shift is enabled.
    zonal_shift=True
)
```

Java:

```java
Vpc vpc;

NetworkLoadBalancer lb = NetworkLoadBalancer.Builder.create(this, "LB")
        .vpc(vpc)
        // Whether deletion protection is enabled.
        .deletionProtection(true)

        // Whether cross-zone load balancing is enabled.
        .crossZoneEnabled(true)

        // Whether the load balancer blocks traffic through the Internet Gateway (IGW).
        .denyAllIgwTraffic(false)

        // Indicates how traffic is distributed among the load balancer Availability Zones.
        .clientRoutingPolicy(ClientRoutingPolicy.AVAILABILITY_ZONE_AFFINITY)

        // Indicates whether zonal shift is enabled.
        .zonalShift(true)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

var lb = new NetworkLoadBalancer(this, "LB", new NetworkLoadBalancerProps {
    Vpc = vpc,
    // Whether deletion protection is enabled.
    DeletionProtection = true,

    // Whether cross-zone load balancing is enabled.
    CrossZoneEnabled = true,

    // Whether the load balancer blocks traffic through the Internet Gateway (IGW).
    DenyAllIgwTraffic = false,

    // Indicates how traffic is distributed among the load balancer Availability Zones.
    ClientRoutingPolicy = ClientRoutingPolicy.AVAILABILITY_ZONE_AFFINITY,

    // Indicates whether zonal shift is enabled.
    ZonalShift = true
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

lb := elbv2.NewNetworkLoadBalancer(this, jsii.String("LB"), &NetworkLoadBalancerProps{
	Vpc: Vpc,
	// Whether deletion protection is enabled.
	DeletionProtection: jsii.Boolean(true),

	// Whether cross-zone load balancing is enabled.
	CrossZoneEnabled: jsii.Boolean(true),

	// Whether the load balancer blocks traffic through the Internet Gateway (IGW).
	DenyAllIgwTraffic: jsii.Boolean(false),

	// Indicates how traffic is distributed among the load balancer Availability Zones.
	ClientRoutingPolicy: elbv2.ClientRoutingPolicy_AVAILABILITY_ZONE_AFFINITY,

	// Indicates whether zonal shift is enabled.
	ZonalShift: jsii.Boolean(true),
})
```

## Members

| Member | Description |
| --- | --- |
| `AVAILABILITY_ZONE_AFFINITY` | 100 percent zonal affinity. |
| `PARTIAL_AVAILABILITY_ZONE_AFFINITY` | 85 percent zonal affinity. |
| `ANY_AVAILABILITY_ZONE` | No zonal affinity. |

## Referenced by

- [`NetworkLoadBalancerProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.NetworkLoadBalancerProps.html).clientRoutingPolicy
