.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.
DescribeClusterSubnetGroupsRequest request1 = new DescribeClusterSubnet
GroupsRequest()
.withClusterSubnetGroupName(clusterSubnetGroupName);
DescribeClusterSubnetGroupsResult result1 = client.describeClusterSub
netGroups(request1);
List<String> subnetNames = new ArrayList<String>();
// We can work with just the first group returned since we requested
info about one group.
for (Subnet subnet : result1.getClusterSubnetGroups().get(0).getSub
nets()) {
subnetNames.add(subnet.getSubnetIdentifier());
}
// Add to existing subnet list.
subnetNames.add(subnetId2);
ModifyClusterSubnetGroupRequest request = new ModifyClusterSubnet
GroupRequest()
.withClusterSubnetGroupName(clusterSubnetGroupName)
.withSubnetIds(subnetNames);
ClusterSubnetGroup result2 = client.modifyClusterSubnetGroup(request);
System.out.println("\nSubnet group modified.");
printResultSubnetGroup(result2);
}
private static void describeClusterSubnetGroups() {
DescribeClusterSubnetGroupsRequest request = new DescribeClusterSubnet
GroupsRequest()
.withClusterSubnetGroupName(clusterSubnetGroupName);
DescribeClusterSubnetGroupsResult result = client.describeClusterSubnet
API Version 2012-12-01
30
Amazon Redshift Management Guide
Cluster Subnet Groups