Creating an Amazon DocumentDB Subnet Group - Amazon DocumentDB

Creating an Amazon DocumentDB Subnet Group

You can use the AWS Management Console or AWS CLI to create an Amazon DocumentDB subnet group.

Using the AWS Management Console

Use the following steps to create an Amazon DocumentDB subnet group.

To create an Amazon DocumentDB subnet group

  1. Sign in to the AWS Management Console, and open the Amazon DocumentDB console at https://console.aws.amazon.com/docdb.

  2. In the navigation pane, choose Subnet groups, then choose Create.

    Tip

    If you don't see the navigation pane on the left side of your screen, choose the menu icon () in the upper-left corner of the page.

  3. On the Create subnet group page:

    1. In the Subnet group details section:

      1. Name—Enter a meaningful name for the subnet group.

      2. Description—Enter a description for the subnet group.

    2. In the Add subnets section:

      1. VPC—In the list, choose a VPC for this subnet group.

      2. Do one of the following:

        • To include all subnets in the chosen VPC, choose Add all the subnets related to this VPC.

        • To specify subnets for this subnet group, do the following for each Availability Zone for which you want to include subnets. You must include at least two Availability Zones.

          1. Availability zone—In the list, choose an Availability Zone.

          2. Subnet—In the list, choose a subnet from the chosen Availability Zone for this subnet group.

          3. Choose Add subnet.

  4. Choose Create. When the subnet group is created, it is listed with your other subnet groups.

    
                     Screenshot: Showing the details of a subnet group.

Using the AWS CLI

Before you can create a subnet group using the AWS CLI, you must first determine which subnets are available. Run the following AWS CLI operation to list the Availability Zones and their subnets.

Parameters:

  • --db-subnet-group—Optional. Specifying a particular subnet group lists the Availability Zones and subnets for that group. Omitting this parameter lists Availability Zones and subnets for all your subnet groups. Specifying the default subnet group lists all the VPC's subnets.

For Linux, macOS, or Unix:

aws docdb describe-db-subnet-groups \ --db-subnet-group-name default \ --query 'DBSubnetGroups[*].[DBSubnetGroupName,Subnets[*].[SubnetAvailabilityZone.Name,SubnetIdentifier]]'

For Windows:

aws docdb describe-db-subnet-groups ^ --db-subnet-group-name default ^ --query 'DBSubnetGroups[*].[DBSubnetGroupName,Subnets[*].[SubnetAvailabilityZone.Name,SubnetIdentifier]]'

Output from this operation looks something like the following (JSON format).

[ [ "default", [ [ "us-east-1a", "subnet-4e26d263" ], [ "us-east-1c", "subnet-afc329f4" ], [ "us-east-1e", "subnet-b3806e8f" ], [ "us-east-1d", "subnet-53ab3636" ], [ "us-east-1b", "subnet-991cb8d0" ], [ "us-east-1f", "subnet-29ab1025" ] ] ] ]

Using the output from the previous operation, you can create a new subnet group. The new subnet group must include subnets from at least two Availability Zones.

Parameters:

  • --db-subnet-group-name—Required. The name for this subnet group.

  • --db-subnet-group-description—Required. The description of this subnet group.

  • --subnet-ids—Required. A list of subnets to include in this subnet group. Example: subnet-53ab3636.

  • --Tags—Optional. A list of tags (key-value pairs) to attach to this subnet group.

The following code creates the subnet group sample-subnet-group with three subnets, subnet-4e26d263, subnet-afc329f4, and subnet-b3806e8f.

For Linux, macOS, or Unix:

aws docdb create-db-subnet-group \ --db-subnet-group-name sample-subnet-group \ --db-subnet-group-description "A sample subnet group" \ --subnet-ids subnet-4e26d263 subnet-afc329f4 subnet-b3806e8f \ --tags Key=tag1,Value=One Key=tag2,Value=2

For Windows:

aws docdb create-db-subnet-group ^ --db-subnet-group-name sample-subnet-group ^ --db-subnet-group-description "A sample subnet group" ^ --subnet-ids subnet-4e26d263 subnet-afc329f4 subnet-b3806e8f ^ --tags Key=tag1,Value=One Key=tag2,Value=2

Output from this operation looks something like the following (JSON format).

{ "DBSubnetGroup": { "DBSubnetGroupDescription": "A sample subnet group", "DBSubnetGroupName": "sample-subnet-group", "Subnets": [ { "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetIdentifier": "subnet-4e26d263", "SubnetStatus": "Active" }, { "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetIdentifier": "subnet-afc329f4", "SubnetStatus": "Active" }, { "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetIdentifier": "subnet-b3806e8f", "SubnetStatus": "Active" } ], "VpcId": "vpc-91280df6", "DBSubnetGroupArn": "arn:aws:rds:us-east-1:123SAMPLE012:subgrp:sample-subnet-group", "SubnetGroupStatus": "Complete" } }