I need to programmatically determine the number of nodes in a Redshift cluster. I was hoping the AWS Java APIs would provide it in a cluster description, but I am not able to locate it. Can anyone point me in the right direction?
Yes, it is possible, via DescribeCluster. Each cluster within the region passed to the client is listed as a Cluster item, which has a NumberOfNodes
attribute. For instance:
final AmazonRedshiftClient client = new AmazonRedshiftClient(credentials).withRegion(com.amazonaws.regions.Regions.US_WEST_2);
final DescribeClustersResult describeResult = client.describeClusters();
describeResult.getClusters()
.stream()
.forEach(cluster -> System.out.println(String.format("Cluster: %s \nNumber of nodes: %d",
cluster.getClusterIdentifier(),
cluster.getNumberOfNodes())));
Gives me:
Cluster: cluster-22gsextori36
Number of nodes: 1
Cluster: cluster-22gsextori38
Number of nodes: 1
Cluster: cluster-22gsextori40
Number of nodes: 1