# IpProtocol

The types of IP addresses provisioned in the VPC.

- Source: [`aws-ec2/lib/vpc.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L231)
- Type last changed: v2.121.0 · 12 Jan 2024

## Example

TypeScript:

```ts
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';

// The VPC and subnet must have associated IPv6 CIDR blocks.
const vpc = new ec2.Vpc(this, 'Vpc', {
  ipProtocol: ec2.IpProtocol.DUAL_STACK,
});
const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc });

const service = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'myService', {
  cluster,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  },
  minHealthyPercent: 100,
  ipAddressType: elbv2.IpAddressType.DUAL_STACK,
});

const applicationLoadBalancedEc2Service = new ecsPatterns.ApplicationLoadBalancedEc2Service(this, 'myService', {
  cluster,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  },
  minHealthyPercent: 100,
  ipAddressType: elbv2.IpAddressType.DUAL_STACK,
});
```

Python:

```python
import aws_cdk.aws_elasticloadbalancingv2 as elbv2

# The VPC and subnet must have associated IPv6 CIDR blocks.
vpc = ec2.Vpc(self, "Vpc",
    ip_protocol=ec2.IpProtocol.DUAL_STACK
)
cluster = ecs.Cluster(self, "EcsCluster", vpc=vpc)

service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "myService",
    cluster=cluster,
    task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
        image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
    ),
    min_healthy_percent=100,
    ip_address_type=elbv2.IpAddressType.DUAL_STACK
)

application_load_balanced_ec2_service = ecs_patterns.ApplicationLoadBalancedEc2Service(self, "myService",
    cluster=cluster,
    task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
        image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample")
    ),
    min_healthy_percent=100,
    ip_address_type=elbv2.IpAddressType.DUAL_STACK
)
```

Java:

```java
import software.amazon.awscdk.services.elasticloadbalancingv2.*;

// The VPC and subnet must have associated IPv6 CIDR blocks.
Vpc vpc = Vpc.Builder.create(this, "Vpc")
        .ipProtocol(IpProtocol.DUAL_STACK)
        .build();
Cluster cluster = Cluster.Builder.create(this, "EcsCluster").vpc(vpc).build();

ApplicationLoadBalancedFargateService service = ApplicationLoadBalancedFargateService.Builder.create(this, "myService")
        .cluster(cluster)
        .taskImageOptions(ApplicationLoadBalancedTaskImageOptions.builder()
                .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                .build())
        .minHealthyPercent(100)
        .ipAddressType(IpAddressType.DUAL_STACK)
        .build();

ApplicationLoadBalancedEc2Service applicationLoadBalancedEc2Service = ApplicationLoadBalancedEc2Service.Builder.create(this, "myService")
        .cluster(cluster)
        .taskImageOptions(ApplicationLoadBalancedTaskImageOptions.builder()
                .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                .build())
        .minHealthyPercent(100)
        .ipAddressType(IpAddressType.DUAL_STACK)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.ElasticLoadBalancingV2;

// The VPC and subnet must have associated IPv6 CIDR blocks.
var vpc = new Vpc(this, "Vpc", new VpcProps {
    IpProtocol = IpProtocol.DUAL_STACK
});
var cluster = new Cluster(this, "EcsCluster", new ClusterProps { Vpc = vpc });

var service = new ApplicationLoadBalancedFargateService(this, "myService", new ApplicationLoadBalancedFargateServiceProps {
    Cluster = cluster,
    TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions {
        Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample")
    },
    MinHealthyPercent = 100,
    IpAddressType = IpAddressType.DUAL_STACK
});

var applicationLoadBalancedEc2Service = new ApplicationLoadBalancedEc2Service(this, "myService", new ApplicationLoadBalancedEc2ServiceProps {
    Cluster = cluster,
    TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions {
        Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample")
    },
    MinHealthyPercent = 100,
    IpAddressType = IpAddressType.DUAL_STACK
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

// The VPC and subnet must have associated IPv6 CIDR blocks.
vpc := ec2.NewVpc(this, jsii.String("Vpc"), &VpcProps{
	IpProtocol: ec2.IpProtocol_DUAL_STACK,
})
cluster := ecs.NewCluster(this, jsii.String("EcsCluster"), &ClusterProps{
	Vpc: Vpc,
})

service := ecsPatterns.NewApplicationLoadBalancedFargateService(this, jsii.String("myService"), &ApplicationLoadBalancedFargateServiceProps{
	Cluster: Cluster,
	TaskImageOptions: &ApplicationLoadBalancedTaskImageOptions{
		Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
	},
	MinHealthyPercent: jsii.Number(100),
	IpAddressType: elbv2.IpAddressType_DUAL_STACK,
})

applicationLoadBalancedEc2Service := ecsPatterns.NewApplicationLoadBalancedEc2Service(this, jsii.String("myService"), &ApplicationLoadBalancedEc2ServiceProps{
	Cluster: Cluster,
	TaskImageOptions: &ApplicationLoadBalancedTaskImageOptions{
		Image: ecs.ContainerImage_*FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
	},
	MinHealthyPercent: jsii.Number(100),
	IpAddressType: elbv2.IpAddressType_DUAL_STACK,
})
```

## Members

| Member | Description |
| --- | --- |
| `IPV4_ONLY` | The vpc will be configured with only IPv4 addresses. |
| `DUAL_STACK` | The vpc will have both IPv4 and IPv6 addresses. |

## Referenced by

- [`VpcProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.VpcProps.html).ipProtocol
