I want to implement the following flow from Java code:
My problem is that when I create an EMR using the SDK I can only retrieve the AWS id of it, something like j-XXXXXXXXXXX. But in order to connect to the JDBC I need the master node IP. How can I obtain the master node IP from the code?
I'm following this JDBC example page
==UPDATE==
I tried using the AmazonElasticMapReduceClient.describeCluster
but could only obtain the public DNS name while I'm looking for the private ip.
AFAIK there is no direct way to get it, but it can be achieved using 2 API calls and searching among them:
public String getMasterNodeIp(AmazonElasticMapReduceClient emr, String emrId) throws Exception {
Cluster cluster = emr.describeCluster(new DescribeClusterRequest().withClusterId(emrId)).getCluster();
ListInstancesResult instances = emr.listInstances(new ListInstancesRequest().withClusterId(emrId));
String masterDnsName = cluster.getMasterPublicDnsName();
for (Instance instance : instances.getInstances()) {
if (instance.getPublicDnsName().equals(masterDnsName)) {
return instance.getPrivateIpAddress();
}
}
throw new Exception("Failed to find master node private ip.");
}