# VpcSubnetGroup

A group of subnets returned by the VPC provider.

The included subnets do NOT have to be symmetric!

- Source: [`cx-api/lib/legacy-moved.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/cx-api/lib/legacy-moved.ts#L881)
- Type last changed: v2.238.0 · 9 Feb 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { cx_api } from 'aws-cdk-lib';
const vpcSubnetGroup: cx_api.VpcSubnetGroup = {
  name: 'name',
  subnets: [{
    availabilityZone: 'availabilityZone',
    routeTableId: 'routeTableId',
    subnetId: 'subnetId',

    // the properties below are optional
    cidr: 'cidr',
  }],
  type: cx_api.VpcSubnetGroupType.PUBLIC,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import cx_api

vpc_subnet_group = cx_api.VpcSubnetGroup(
    name="name",
    subnets=[cx_api.VpcSubnet(
        availability_zone="availabilityZone",
        route_table_id="routeTableId",
        subnet_id="subnetId",

        # the properties below are optional
        cidr="cidr"
    )],
    type=cx_api.VpcSubnetGroupType.PUBLIC
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.cxapi.*;

VpcSubnetGroup vpcSubnetGroup = VpcSubnetGroup.builder()
        .name("name")
        .subnets(List.of(VpcSubnet.builder()
                .availabilityZone("availabilityZone")
                .routeTableId("routeTableId")
                .subnetId("subnetId")

                // the properties below are optional
                .cidr("cidr")
                .build()))
        .type(VpcSubnetGroupType.PUBLIC)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.CXAPI;

var vpcSubnetGroup = new VpcSubnetGroup {
    Name = "name",
    Subnets = new [] { new VpcSubnet {
        AvailabilityZone = "availabilityZone",
        RouteTableId = "routeTableId",
        SubnetId = "subnetId",

        // the properties below are optional
        Cidr = "cidr"
    } },
    Type = VpcSubnetGroupType.PUBLIC
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

vpcSubnetGroup := &VpcSubnetGroup{
	Name: jsii.String("name"),
	Subnets: []VpcSubnet{
		&VpcSubnet{
			AvailabilityZone: jsii.String("availabilityZone"),
			RouteTableId: jsii.String("routeTableId"),
			SubnetId: jsii.String("subnetId"),

			// the properties below are optional
			Cidr: jsii.String("cidr"),
		},
	},
	Type: awscdk.Cx_api.VpcSubnetGroupType_PUBLIC,
}
```

## Properties

- `name`: string (required) — The name of the subnet group, determined by looking at the tags of of the subnets that belong to it.

- `subnets`: [VpcSubnet](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.cx_api.VpcSubnet.html)[] (required) — The subnets that are part of this group.

  There is no condition that the subnets have to be symmetric
  in the group.

- `type`: [VpcSubnetGroupType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.cx_api.VpcSubnetGroupType.html) (required) — The type of the subnet group.
