# SubnetType

The type of Subnet.

- Source: [`aws-ec2/lib/vpc.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L251)
- Type last changed: v2.41.0 · 8 Sep 2022

## Example

```ts
declare const vpc: ec2.Vpc;
const cluster = new docdb.DatabaseCluster(this, 'Database', {
  masterUser: {
    username: 'myuser', // NOTE: 'admin' is reserved by DocumentDB
    excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/" and is also used for eventually created rotations
    secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
  },
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
  vpcSubnets: {
    subnetType: ec2.SubnetType.PUBLIC,
  },
  vpc,
  copyTagsToSnapshot: true  // whether to save the cluster tags when creating the snapshot.
});
```

## Members

| Member | Description |
| --- | --- |
| `PRIVATE_ISOLATED` | Isolated Subnets do not route traffic to the Internet (in this VPC), and as such, do not require NAT gateways. |
| `PRIVATE_WITH_EGRESS` | Subnet that routes to the internet, but not vice versa. |
| `PRIVATE_WITH_NAT` | Subnet that routes to the internet (via a NAT gateway), but not vice versa. |
| `PUBLIC` | Subnet connected to the Internet. |

## Referenced by

- [`ISubnetV2`](/v2/docs/@aws-cdk_aws-ec2-alpha.ISubnetV2).subnetType
- [`SubnetConfiguration`](/v2/docs/aws-cdk-lib.aws_ec2.SubnetConfiguration).subnetType
- [`SubnetSelection`](/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection).subnetType
- [`SubnetV2`](/v2/docs/@aws-cdk_aws-ec2-alpha.SubnetV2).subnetType
- [`SubnetV2Attributes`](/v2/docs/@aws-cdk_aws-ec2-alpha.SubnetV2Attributes).subnetType
- [`SubnetV2Props`](/v2/docs/@aws-cdk_aws-ec2-alpha.SubnetV2Props).subnetType
