# VpcAttributes

Properties that reference an external Vpc.

Used as argument in: [Vpc.fromVpcAttributes](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Vpc.html#fromvpcattributes)

- 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#L780)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

TypeScript:

```ts
const vpc = ec2.Vpc.fromVpcAttributes(this, 'VPC', {
  vpcId: 'vpc-1234',
  availabilityZones: ['us-east-1a', 'us-east-1b'],

  // Either pass literals for all IDs
  publicSubnetIds: ['s-12345', 's-67890'],

  // OR: import a list of known length
  privateSubnetIds: Fn.importListValue('PrivateSubnetIds', 2),

  // OR: split an imported string to a list of known length
  isolatedSubnetIds: Fn.split(',', ssm.StringParameter.valueForStringParameter(this, `MyParameter`), 2),
});
```

Python:

```python
vpc = ec2.Vpc.from_vpc_attributes(self, "VPC",
    vpc_id="vpc-1234",
    availability_zones=["us-east-1a", "us-east-1b"],

    # Either pass literals for all IDs
    public_subnet_ids=["s-12345", "s-67890"],

    # OR: import a list of known length
    private_subnet_ids=Fn.import_list_value("PrivateSubnetIds", 2),

    # OR: split an imported string to a list of known length
    isolated_subnet_ids=Fn.split(",", ssm.StringParameter.value_for_string_parameter(self, "MyParameter"), 2)
)
```

Java:

```java
IVpc vpc = Vpc.fromVpcAttributes(this, "VPC", VpcAttributes.builder()
        .vpcId("vpc-1234")
        .availabilityZones(List.of("us-east-1a", "us-east-1b"))

        // Either pass literals for all IDs
        .publicSubnetIds(List.of("s-12345", "s-67890"))

        // OR: import a list of known length
        .privateSubnetIds(Fn.importListValue("PrivateSubnetIds", 2))

        // OR: split an imported string to a list of known length
        .isolatedSubnetIds(Fn.split(",", StringParameter.valueForStringParameter(this, "MyParameter"), 2))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = Vpc.FromVpcAttributes(this, "VPC", new VpcAttributes {
    VpcId = "vpc-1234",
    AvailabilityZones = new [] { "us-east-1a", "us-east-1b" },

    // Either pass literals for all IDs
    PublicSubnetIds = new [] { "s-12345", "s-67890" },

    // OR: import a list of known length
    PrivateSubnetIds = Fn.ImportListValue("PrivateSubnetIds", 2),

    // OR: split an imported string to a list of known length
    IsolatedSubnetIds = Fn.Split(",", StringParameter.ValueForStringParameter(this, "MyParameter"), 2)
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.Vpc_FromVpcAttributes(this, jsii.String("VPC"), &VpcAttributes{
	VpcId: jsii.String("vpc-1234"),
	AvailabilityZones: []*string{
		jsii.String("us-east-1a"),
		jsii.String("us-east-1b"),
	},

	// Either pass literals for all IDs
	PublicSubnetIds: []*string{
		jsii.String("s-12345"),
		jsii.String("s-67890"),
	},

	// OR: import a list of known length
	PrivateSubnetIds: awscdk.Fn_ImportListValue(jsii.String("PrivateSubnetIds"), jsii.Number(2)),

	// OR: split an imported string to a list of known length
	IsolatedSubnetIds: awscdk.Fn_Split(jsii.String(","), ssm.StringParameter_ValueForStringParameter(this, jsii.String("MyParameter")), jsii.Number(2)),
})
```

## Properties

- `availabilityZones`: string[] (required) — List of availability zones for the subnets in this VPC.

- `isolatedSubnetIds`: string[] — List of isolated subnet IDs.

  **Default:** The VPC does not have any isolated subnets

  Must be undefined or match the availability zones in length and order.

- `isolatedSubnetIpv4CidrBlocks`: string[] — List of IPv4 CIDR blocks for the isolated subnets.

  **Default:** Retrieving the IPv4 CIDR block of any isolated subnet will fail

  Must be undefined or have an entry for every isolated subnet group.

- `isolatedSubnetNames`: string[] — List of names for the isolated subnets.

  **Default:** All isolated subnets will have the name `Isolated`

  Must be undefined or have a name for every isolated subnet group.

- `isolatedSubnetRouteTableIds`: string[] — List of IDs of route tables for the isolated subnets.

  **Default:** Retrieving the route table ID of any isolated subnet will fail

  Must be undefined or have a name for every isolated subnet group.

- `privateSubnetIds`: string[] — List of private subnet IDs.

  **Default:** The VPC does not have any private subnets

  Must be undefined or match the availability zones in length and order.

- `privateSubnetIpv4CidrBlocks`: string[] — List of IPv4 CIDR blocks for the private subnets.

  **Default:** Retrieving the IPv4 CIDR block of any private subnet will fail

  Must be undefined or have an entry for every private subnet group.

- `privateSubnetNames`: string[] — List of names for the private subnets.

  **Default:** All private subnets will have the name `Private`

  Must be undefined or have a name for every private subnet group.

- `privateSubnetRouteTableIds`: string[] — List of IDs of route tables for the private subnets.

  **Default:** Retrieving the route table ID of any private subnet will fail

  Must be undefined or have a name for every private subnet group.

- `publicSubnetIds`: string[] — List of public subnet IDs.

  **Default:** The VPC does not have any public subnets

  Must be undefined or match the availability zones in length and order.

- `publicSubnetIpv4CidrBlocks`: string[] — List of IPv4 CIDR blocks for the public subnets.

  **Default:** Retrieving the IPv4 CIDR block of any public subnet will fail

  Must be undefined or have an entry for every public subnet group.

- `publicSubnetNames`: string[] — List of names for the public subnets.

  **Default:** All public subnets will have the name `Public`

  Must be undefined or have a name for every public subnet group.

- `publicSubnetRouteTableIds`: string[] — List of IDs of route tables for the public subnets.

  **Default:** Retrieving the route table ID of any public subnet will fail

  Must be undefined or have a name for every public subnet group.

- `region`: string — The region the VPC is in.

  **Default:** The region of the stack where the VPC belongs to

- `vpcCidrBlock`: string — VPC's CIDR range.

  **Default:** Retrieving the CIDR from the VPC will fail

- `vpcId`: string (required) — VPC's identifier.

- `vpnGatewayId`: string — VPN gateway's identifier.
