Skip to content
v2.277.0

SubnetType Enum ​

The type of Subnet.

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.
});
python
# vpc: ec2.Vpc

cluster = docdb.DatabaseCluster(self, "Database",
    master_user=docdb.Login(
        username="myuser",  # NOTE: 'admin' is reserved by DocumentDB
        exclude_characters="\"@/:",  # optional, defaults to the set "\"@/" and is also used for eventually created rotations
        secret_name="/myapp/mydocdb/masteruser"
    ),
    instance_type=ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
    vpc_subnets=ec2.SubnetSelection(
        subnet_type=ec2.SubnetType.PUBLIC
    ),
    vpc=vpc,
    copy_tags_to_snapshot=True
)
java
Vpc vpc;

DatabaseCluster cluster = DatabaseCluster.Builder.create(this, "Database")
        .masterUser(Login.builder()
                .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")
                .build())
        .instanceType(InstanceType.of(InstanceClass.MEMORY5, InstanceSize.LARGE))
        .vpcSubnets(SubnetSelection.builder()
                .subnetType(SubnetType.PUBLIC)
                .build())
        .vpc(vpc)
        .copyTagsToSnapshot(true)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

var cluster = new DatabaseCluster(this, "Database", new DatabaseClusterProps {
    MasterUser = new Login {
        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"
    },
    InstanceType = InstanceType.Of(InstanceClass.MEMORY5, InstanceSize.LARGE),
    VpcSubnets = new SubnetSelection {
        SubnetType = SubnetType.PUBLIC
    },
    Vpc = vpc,
    CopyTagsToSnapshot = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

cluster := docdb.NewDatabaseCluster(this, jsii.String("Database"), &DatabaseClusterProps{
	MasterUser: &Login{
		Username: jsii.String("myuser"),
		 // NOTE: 'admin' is reserved by DocumentDB
		ExcludeCharacters: jsii.String("\"@/:"),
		 // optional, defaults to the set "\"@/" and is also used for eventually created rotations
		SecretName: jsii.String("/myapp/mydocdb/masteruser"),
	},
	InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_MEMORY5, ec2.InstanceSize_LARGE),
	VpcSubnets: &SubnetSelection{
		SubnetType: ec2.SubnetType_PUBLIC,
	},
	Vpc: Vpc,
	CopyTagsToSnapshot: jsii.Boolean(true),
})

Members ​

MemberDescription
PRIVATE_ISOLATEDIsolated Subnets do not route traffic to the Internet (in this VPC), and as such, do not require NAT gateways.
PRIVATE_WITH_EGRESSSubnet that routes to the internet, but not vice versa.
PRIVATE_WITH_NAT deprecateduse PRIVATE_WITH_EGRESS
PUBLICSubnet connected to the Internet.

Referenced by ​