Search code examples
hadoopamazon-web-serviceshiveemr

Not able to connect to hive on AWS EMR using java


I have setup AWS EMR cluster with hive. I want to connect to hive thrift server from my local machine using java. I tried following code-

Class.forName("com.amazon.hive.jdbc3.HS2Driver");
con = DriverManager.getConnection("jdbc:hive2://ec2XXXX.compute-1.amazonaws.com:10000/default","hadoop", "");

http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/HiveJDBCDriver.html.As mentioned in the developer guide, added jars related with hive jdbc driver to class path. But I am getting exception when trying to get connection. I was able to connect to hive server on simple hadoop cluster using above code (with different jdbc driver). Can someone please suggest if I am missing something? Is it possible to connect to hive server on AWS EMR from local machine using hive jdbc?


Solution

  • (Merged Answer from the comments)

    Hive is running on port 10000 but only locally, you have to create a ssh tunnel to the emr.

    The following is from the documentation for hive 0.13.1

    Create Tunnel

    ssh -o ServerAliveInterval=10 -i path-to-key-file -N -L 10000:localhost:10000 hadoop@master-public-dns-name 
    

    Connect to JDBC

     jdbc:hive2://localhost:10000/default