

# Subnets and subnet groups
<a name="subnetgroups"></a>

A *subnet group* is a collection of subnets (typically private) that you can designate for your clusters running in an Amazon Virtual Private Cloud (VPC) environment.

When you create a cluster in an Amazon VPC, you can specify a subnet group or use the default one provided. MemoryDB uses that subnet group to choose a subnet and IP addresses within that subnet to associate with your nodes.

This section covers how to create and leverage subnets and subnet groups to manage access to your MemoryDB resources. 

For more information about subnet group usage in an Amazon VPC environment, see [Step 3: Authorize access to the cluster](getting-started.md#getting-started.authorizeaccess).


**Supported MemoryDB AZ IDs**  

| Region Name/Region | Supported AZ IDs | 
| --- | --- | 
| US East (Ohio) Region `us-east-2` | `use2-az1, use2-az2, use2-az3` | 
| US East (N. Virginia) Region `us-east-1` | `use1-az1, use1-az2, use1-az4, use1-az5, use1-az6` | 
| US West (N. California) Region `us-west-1` | `usw1-az1, usw1-az2, usw1-az3` | 
| US West (Oregon) Region `us-west-2` | `usw2-az1, usw2-az2, usw2-az3, usw2-az4` | 
| Canada (Central) Region `ca-central-1` | `cac1-az1, cac1-az2, cac1-az4` | 
| Asia Pacific (Hong Kong) Region `ap-east-1` | `ape1-az1, ape1-az2, ape1-az3` | 
| Asia Pacific (Mumbai) Region `ap-south-1` | `aps1-az1, aps1-az2, aps1-az3` | 
| Asia Pacific (Tokyo) Region `ap-northeast-1` | `apne1-az1, apne1-az2, apne1-az4` | 
| Asia Pacific (Seoul) Region `ap-northeast-2` | `apne2-az1, apne2-az2, apne2-az3` | 
| Asia Pacific (Singapore) Region `ap-southeast-1` | `apse1-az1, apse1-az2, apse1-az3` | 
| Asia Pacific (Sydney) Region `ap-southeast-2` | apse2-az1, apse2-az2, apse2-az3  | 
| Europe (Frankfurt) Region `eu-central-1` | `euc1-az1, euc1-az2, euc1-az3` | 
| Europe (Ireland) Region `eu-west-1` | `euw1-az1, euw1-az2, euw1-az3` | 
| Europe (London) Region `eu-west-2` | `euw2-az1, euw2-az2, euw2-az3` | 
| EU (Paris) Region `eu-west-3` | `euw3-az1, euw3-az2, euw3-az3` | 
| Europe (Stockholm) Region `eu-north-1` | `eun1-az1, eun1-az2, eun1-az3 ` | 
| Europe (Milan) Region `eu-south-1` | `eus1-az1, eus1-az2, eus1-az3 ` | 
| South America (São Paulo) Region `sa-east-1` | `sae1-az1, sae1-az2, sae1-az3` | 
| China (Beijing) Region `cn-north-1` | `cnn1-az1, cnn1-az2` | 
| China (Ningxia) Region `cn-northwest-1` | `cnw1-az1, cnw1-az2, cnw1-az3` | 
|  `us-gov-east-1` | `usge1-az1, usge1-az2, usge1-az3` | 
|  `us-gov-west-1` | `usgw1-az1, usgw1-az2, usgw1-az3` | 
| Europe (Spain) Region `eu-south-2` | `eus2-az1, eus2-az2, eus2-az3` | 

**Topics**
+ [MemoryDB and IPV6](subnetgroups.ipv6.md)
+ [Creating a subnet group](subnetgroups.creating.md)
+ [Updating a subnet group](subnetgroups.modifying.md)
+ [Viewing subnet group details](subnetgroups.Viewing.md)
+ [Deleting a subnet group](subnetgroups.deleting.md)

# MemoryDB and IPV6
<a name="subnetgroups.ipv6"></a>

You can create new dual stack and ipv6-only clusters with both Valkey and Redis OSS engines, by providing subnet groups with dual stack and ipv6-only subnets. You cannot change the network type for an existing cluster.

With this functionality you can:
+ Create ipv4-only and dual stack clusters on dual stack subnets.
+ Create ipv6-only clusters on ipv6-only subnets.
+ Create new subnet groups to support ipv4-only, dual stack, and ipv6-only subnets.
+ Modify existing subnet groups to include additional subnets from the underlying VPC.
+ Modify existing subnets in subnet groups
  + Add IPv6 only subnets to subnet groups configured for IPv6
  + Add IPv4 or dual stack subnets to subnet groups configured for IPv4 and dual stack support
+ Discover all the nodes in the cluster with ipv4 OR ipv6 addresses, through engine discovery commands for dual stack and ipv6 clusters. These discovery commands include `redis_info`, `redis_cluster`, and similar.
+ Discover the ipv4 and ipv6 addresses of all the nodes in the cluster, through DNS discovery commands for dual stack and ipv6 clusters.

# Creating a subnet group
<a name="subnetgroups.creating"></a>

When you create a new subnet group, note the number of available IP addresses. If the subnet has very few free IP addresses, you might be constrained as to how many more nodes you can add to the cluster. To resolve this issue, you can assign one or more subnets to a subnet group so that you have a sufficient number of IP addresses in your cluster's Availability Zone. After that, you can add more nodes to your cluster.

The following procedures show you how to create a subnet group called `mysubnetgroup` (console), the AWS CLI, and the MemoryDB API.

## Creating a subnet group (Console)
<a name="subnetgroups.creatingclusters.viewdetails"></a>

The following procedure shows how to create a subnet group (console).

**To create a subnet group (Console)**

1. Sign in to the AWS Management Console, and open the MemoryDB console at [https://console.aws.amazon.com/memorydb/](https://console.aws.amazon.com/memorydb/).

1. In the left navigation pane, choose **Subnet Groups**.

1. Choose **Create Subnet Group**.

1. In the **Create Subnet Group** page, do the following: 

   1. In the **Name** box, type a name for your subnet group.

      Cluster naming constraints are as follows:
      + Must contain 1–40 alphanumeric characters or hyphens.
      + Must begin with a letter.
      + Can't contain two consecutive hyphens.
      + Can't end with a hyphen.

   1. In the **Description** box, type a description for your subnet group.

   1. In the **VPC ID** box, choose the Amazon VPC that you created. If you have not created one, choose the **Create VPC** button and follow the steps to create one. 

   1. In **Selected subnets**, choose the Availability Zone and ID of your private subnet, and then choose **Choose**.

1. For **Tags**, you can optionally apply tags to search and filter your subnets or track your AWS costs. 

1. When all the settings are as you want them, choose **Create**.

1. In the confirmation message that appears, choose **Close**.

Your new subnet group appears in the **Subnet Groups** list of the MemoryDB console. At the bottom of the window you can choose the subnet group to see details, such as all of the subnets associated with this group.

## Creating a subnet group (AWS CLI)
<a name="subnetgroups.creating.cli"></a>

At a command prompt, use the command `create-subnet-group` to create a subnet group.

For Linux, macOS, or Unix:

```
aws memorydb create-subnet-group \
    --subnet-group-name mysubnetgroup \
    --description "Testing" \
    --subnet-ids subnet-53df9c3a
```

For Windows:

```
aws memorydb create-subnet-group ^
    --subnet-group-name mysubnetgroup ^
    --description "Testing" ^
    --subnet-ids subnet-53df9c3a
```

This command should produce output similar to the following:

```
    {
        "SubnetGroup": {
            "Subnets": [
                {
                    "Identifier": "subnet-53df9c3a", 
                    "AvailabilityZone": {
                    "Name": "us-east-1a"
                    }
                }
            ], 
            "VpcId": "vpc-3cfaef47", 
            "Name": "mysubnetgroup", 
            "ARN": "arn:aws:memorydb:us-east-1:012345678912:subnetgroup/mysubnetgroup", 
            "Description": "Testing"
        }
    }
```

For more information, see the AWS CLI topic [create-subnet-group](https://docs.aws.amazon.com/cli/latest/reference/memorydb/create-subnet-group.html).

## Creating a subnet group (MemoryDB API)
<a name="subnetgroups.creating.api"></a>

Using the MemoryDB API, call `CreateSubnetGroup` with the following parameters: 
+ `SubnetGroupName=``mysubnetgroup`
+ `Description=``Testing`
+ `SubnetIds.member.1=``subnet-53df9c3a`

# Updating a subnet group
<a name="subnetgroups.modifying"></a>

You can update a subnet group's description, or modify the list of subnet IDs associated with the subnet group. You cannot delete a subnet ID from a subnet group if a cluster is currently using that subnet.

The following procedures show you how to update a subnet group.

## Updating subnet groups (Console)
<a name="subnetgroups.modifyingclusters.viewdetails"></a>

**To update a subnet group**

1. Sign in to the AWS Management Console and open the MemoryDB console at [https://console.aws.amazon.com/memorydb/](https://console.aws.amazon.com/memorydb/).

1. In the left navigation pane, choose **Subnet Groups**.

1. In the list of subnet groups, choose the one you want to modify.

1. **Name**, **VPCId** and **Description** fields are not modifiable. 

1. In the **Selected subnets** section click **Manage** to make any changes to the Availability Zones you need for the subnets. To save your changes, choose **Save**.

## Updating subnet groups (AWS CLI)
<a name="subnetgroups.modifying.cli"></a>

At a command prompt, use the command `update-subnet-group` to update a subnet group.

For Linux, macOS, or Unix:

```
aws memorydb update-subnet-group \
    --subnet-group-name mysubnetgroup \
    --description "New description" \
    --subnet-ids "subnet-42df9c3a" "subnet-48fc21a9"
```

For Windows:

```
aws memorydb update-subnet-group ^
    --subnet-group-name mysubnetgroup ^
    --description "New description" ^
    --subnet-ids "subnet-42df9c3a" "subnet-48fc21a9"
```

This command should produce output similar to the following:

```
{
    "SubnetGroup": {
        "VpcId": "vpc-73cd3c17", 
        "Description": "New description", 
        "Subnets": [
            {
                "Identifier": "subnet-42dcf93a", 
                "AvailabilityZone": {
                    "Name": "us-east-1a"
                }
            },
            {
                "Identifier": "subnet-48fc12a9", 
                "AvailabilityZone": {
                    "Name": "us-east-1a"
                }
            }
        ], 
        "Name": "mysubnetgroup",
        "ARN": "arn:aws:memorydb:us-east-1:012345678912:subnetgroup/mysubnetgroup",
    }
}
```

For more information, see the AWS CLI topic [update-subnet-group](https://docs.aws.amazon.com/cli/latest/reference/memorydb/update-subnet-group.html).

## Updating subnet groups (MemoryDB API)
<a name="subnetgroups.modifying.api"></a>

Using the MemoryDB API, call `UpdateSubnetGroup` with the following parameters:
+ `SubnetGroupName=``mysubnetgroup`
+ Any other parameters whose values you want to change. This example uses `Description=``New%20description` to change the description of the subnet group.

**Example**  

```
https://memory-db.us-east-1.amazonaws.com/
    ?Action=UpdateSubnetGroup
    &Description=New%20description
    &SubnetGroupName=mysubnetgroup
    &SubnetIds.member.1=subnet-42df9c3a
    &SubnetIds.member.2=subnet-48fc21a9
    &SignatureMethod=HmacSHA256
    &SignatureVersion=4
    &Timestamp=20141201T220302Z
    &Version=2014-12-01
    &X-Amz-Algorithm=Amazon4-HMAC-SHA256
    &X-Amz-Credential=<credential>
    &X-Amz-Date=20141201T220302Z
    &X-Amz-Expires=20141201T220302Z
    &X-Amz-Signature=<signature>
    &X-Amz-SignedHeaders=Host
```

**Note**  
When you create a new subnet group, take note the number of available IP addresses. If the subnet has very few free IP addresses, you might be constrained as to how many more nodes you can add to the cluster. To resolve this issue, you can assign one or more subnets to a subnet group so that you have a sufficient number of IP addresses in your cluster's Availability Zone. After that, you can add more nodes to your cluster.

# Viewing subnet group details
<a name="subnetgroups.Viewing"></a>

The following procedures show you how to view details a subnet group.

## Viewing details of subnet groups (console)
<a name="subnetgroups.Viewingclusters.viewdetails"></a>

**To view details of a subnet group (Console)**

1. Sign in to the AWS Management Console and open the MemoryDB console at [https://console.aws.amazon.com/memorydb/](https://console.aws.amazon.com/memorydb/).

1. In the left navigation pane, choose **Subnet Groups**.

1. On the **Subnet groups** page, choose the subnet group under **Name** or enter the subnet group's name in the search bar.

1. On the **Subnet groups** page, choose the subnet group under **Name** or enter the subnet group's name in the search bar.

1. Under **Subnet group settings** you can view the name,description, VPC ID and Amazon Resource Name (ARN) of the subnet group.

1. Under **Subnets** you can view the Availability Zones, Subnet IDs and CIDR blocks of the subnet group

1. Under **Tags** you can view any tags associated with the subnet group.

## Viewing subnet groups details (AWS CLI)
<a name="subnetgroups.Viewing.cli"></a>

At a command prompt, use the command `describe-subnet-groups` to view a specified subnet group's details.

For Linux, macOS, or Unix:

```
aws memorydb describe-subnet-groups \
    --subnet-group-name mysubnetgroup
```

For Windows:

```
aws memorydb describe-subnet-groups ^
    --subnet-group-name mysubnetgroup
```

This command should produce output similar to the following:

```
{
  "subnetgroups": [
    {
      "Subnets": [
        {
          "Identifier": "subnet-060cae3464095de6e", 
          "AvailabilityZone": {
            "Name": "us-east-1a"
          }
        }, 
        {
          "Identifier": "subnet-049d11d4aa78700c3", 
          "AvailabilityZone": {
            "Name": "us-east-1c"
          }
        }, 
        {
          "Identifier": "subnet-0389d4c4157c1edb4", 
          "AvailabilityZone": {
            "Name": "us-east-1d"
          }
        }
      ], 
      "VpcId": "vpc-036a8150d4300bcf2", 
      "Name": "mysubnetgroup", 
      "ARN": "arn:aws:memorydb:us-east-1:53791xzzz7620:subnetgroup/mysubnetgroup", 
      "Description": "test"
    }
  ]
}
```

To view details on all subnet groups, use the same command but without specifying a subnet group name.

```
aws memorydb describe-subnet-groups
```

For more information, see the AWS CLI topic [describe-subnet-groups](https://docs.aws.amazon.com/cli/latest/reference/memorydb/update-subnet-group.html).

## Viewing subnet groups (MemoryDB API)
<a name="subnetgroups.Viewing.api"></a>

Using the MemoryDB API, call `DescribeSubnetGroups` with the following parameters:

`SubnetGroupName=``mysubnetgroup`

**Example**  

```
https://memory-db.us-east-1.amazonaws.com/
    ?Action=UpdateSubnetGroup
    &Description=New%20description
    &SubnetGroupName=mysubnetgroup
    &SubnetIds.member.1=subnet-42df9c3a
    &SubnetIds.member.2=subnet-48fc21a9
    &SignatureMethod=HmacSHA256
    &SignatureVersion=4
    &Timestamp=20211801T220302Z
    &Version=2021-01-01
    &X-Amz-Algorithm=Amazon4-HMAC-SHA256
    &X-Amz-Credential=<credential>
    &X-Amz-Date=20210801T220302Z
    &X-Amz-Expires=20210801T220302Z
    &X-Amz-Signature=<signature>
    &X-Amz-SignedHeaders=Host
```

# Deleting a subnet group
<a name="subnetgroups.deleting"></a>

If you decide that you no longer need your subnet group, you can delete it. You cannot delete a subnet group if it is currently in use by a cluster. You also cannot delete a subnet group on a cluster with Multi-AZ enabled if doing so leaves that cluster with fewer than two subnets. You must first uncheck **Multi-AZ** and then delete the subnet.

The following procedures show you how to delete a subnet group.

## Deleting a subnet group (Console)
<a name="subnetgroups.deletingclusters.viewdetails"></a>

**To delete a subnet group**

1. Sign in to the AWS Management Console and open the MemoryDB console at [https://console.aws.amazon.com/memorydb/](https://console.aws.amazon.com/memorydb/).

1. In the left navigation pane, choose **Subnet Groups**.

1. In the list of subnet groups, choose the one you want to delete, choose **Actions** and then choose **Delete**.
**Note**  
You cannot delete a default subnet group or one that is associated with any clusters.

1. The **Delete Subnet Groups** confirmation screen will appear.

1. To delete the subnet group, enter `delete` in the confirmation text box. To keep the subnet group, choose **Cancel**.

## Deleting a subnet group (AWS CLI)
<a name="subnetgroups.deleting.cli"></a>

Using the AWS CLI, call the command **delete-subnet-group** with the following parameter:
+ `--subnet-group-name` *mysubnetgroup*

For Linux, macOS, or Unix:

```
aws memorydb delete-subnet-group \
    --subnet-group-name mysubnetgroup
```

For Windows:

```
aws memorydb delete-subnet-group ^
    --subnet-group-name mysubnetgroup
```

For more information, see the AWS CLI topic [delete-subnet-group](https://docs.aws.amazon.com/cli/latest/reference/memorydb/delete-subnet-group.html).

## Deleting a subnet group (MemoryDB API)
<a name="subnetgroups.deleting.api"></a>

Using the MemoryDB API, call `DeleteSubnetGroup` with the following parameter:
+ `SubnetGroupName=mysubnetgroup`

**Example**  

```
https://memory-db.us-east-1.amazonaws.com/
    ?Action=DeleteSubnetGroup
    &SubnetGroupName=mysubnetgroup
    &SignatureMethod=HmacSHA256
    &SignatureVersion=4
    &Timestamp=20210801T220302Z
    &Version=2021-01-01
    &X-Amz-Algorithm=Amazon4-HMAC-SHA256
    &X-Amz-Credential=<credential>
    &X-Amz-Date=20210801T220302Z
    &X-Amz-Expires=20210801T220302Z
    &X-Amz-Signature=<signature>
    &X-Amz-SignedHeaders=Host
```

This command produces no output.

For more information, see the MemoryDB API topic [DeleteSubnetGroup](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_DeleteSubnetGroup.html).