aws-cdk-lib.aws_rds.SubnetGroup

class SubnetGroup (construct)

LanguageType name
.NETAmazon.CDK.AWS.RDS.SubnetGroup
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsrds#SubnetGroup
Javasoftware.amazon.awscdk.services.rds.SubnetGroup
Pythonaws_cdk.aws_rds.SubnetGroup
TypeScript (source)aws-cdk-lib » aws_rds » SubnetGroup

Implements IConstruct, IDependable, IResource, ISubnetGroup

Class for creating a RDS DB subnet group.

Example

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_rds as rds } from 'aws-cdk-lib';

declare const subnet: ec2.Subnet;
declare const subnetFilter: ec2.SubnetFilter;
declare const vpc: ec2.Vpc;
const subnetGroup = new rds.SubnetGroup(this, 'MySubnetGroup', {
  description: 'description',
  vpc: vpc,

  // the properties below are optional
  removalPolicy: cdk.RemovalPolicy.DESTROY,
  subnetGroupName: 'subnetGroupName',
  vpcSubnets: {
    availabilityZones: ['availabilityZones'],
    onePerAz: false,
    subnetFilters: [subnetFilter],
    subnetGroupName: 'subnetGroupName',
    subnets: [subnet],
    subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
  },
});

Initializer

new SubnetGroup(scope: Construct, id: string, props: SubnetGroupProps)

Parameters

  • scope Construct
  • id string
  • props SubnetGroupProps

Construct Props

NameTypeDescription
descriptionstringDescription of the subnet group.
vpcIVpcThe VPC to place the subnet group in.
removalPolicy?RemovalPolicyThe removal policy to apply when the subnet group are removed from the stack or replaced during an update.
subnetGroupName?stringThe name of the subnet group.
vpcSubnets?SubnetSelectionWhich subnets within the VPC to associate with this group.

description

Type: string

Description of the subnet group.


vpc

Type: IVpc

The VPC to place the subnet group in.


removalPolicy?

Type: RemovalPolicy (optional, default: RemovalPolicy.DESTROY)

The removal policy to apply when the subnet group are removed from the stack or replaced during an update.


subnetGroupName?

Type: string (optional, default: a name is generated)

The name of the subnet group.


vpcSubnets?

Type: SubnetSelection (optional, default: private subnets)

Which subnets within the VPC to associate with this group.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
subnetGroupNamestringThe name of the subnet group.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


subnetGroupName

Type: string

The name of the subnet group.

Methods

NameDescription
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.
static fromSubnetGroupName(scope, id, subnetGroupName)Imports an existing subnet group by name.

applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromSubnetGroupName(scope, id, subnetGroupName)

public static fromSubnetGroupName(scope: Construct, id: string, subnetGroupName: string): ISubnetGroup

Parameters

  • scope Construct
  • id string
  • subnetGroupName string

Returns

  • ISubnetGroup

Imports an existing subnet group by name.