User guide
• Creating a cluster subnet group.
• Listing metadata about a cluster subnet group.
• Modifying a cluster subnet group.
For step-by-step instructions to run the following example, see Running Java Examples for Amazon
Redshift Using Eclipse (p. 130).You need to update the code and provide a cluster subnet group name
and two subnet identifiers.
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.redshift.AmazonRedshiftClient;
import com.amazonaws.services.redshift.model.*;
public class CreateAndModifyClusterSubnetGroup {
public static AmazonRedshiftClient client;
public static String clusterSubnetGroupName = "***provide a cluster subnet
group name ****";
// You can use the VPC console to find subnet IDs to use.
public static String subnetId1 = "***provide a subnet ID****";
public static String subnetId2 = "***provide a subnet ID****";
public static void main(String[] args) throws IOException {
AWSCredentials credentials = new PropertiesCredentials(
CreateAndModifyClusterSubnetGroup.class
.getResourceAsStream("AwsCredentials.properties"));
client = new AmazonRedshiftClient(credentials);
try {
createClusterSubnetGroup();
describeClusterSubnetGroups();
modifyClusterSubnetGroup();
} catch (Exception e) {
System.err.println("Operation failed: " + e.getMessage());
}
}
private static void createClusterSubnetGroup() {
CreateClusterSubnetGroupRequest request = new CreateClusterSubnet
GroupRequest()
.withClusterSubnetGroupName(clusterSubnetGroupName)
.withDescription("my cluster subnet group")
.withSubnetIds(subnetId1);
client.createClusterSubnetGroup(request);
System.out.println("Created cluster subnet group: " + clusterSubnetGroup
Name);
}
private static void modifyClusterSubnetGroup() {
// Get existing subnet list.
API Version 2012-12-01
40
Amazon Redshift Management Guide
Cluster Subnet Groups