2

Just wondering how I get the hostname, i.e. the result of running 'hostname' on the command prompt, of an AWS machine (RHEL) via the Java API.

I can call the following

com.amazonaws.services.ec2.model.Instance awsInstance = ...
awsInstance.getPublicIpAddress())
awsInstance.getPrivateIpAddress())
awsInstance.getPrivateDnsName())
awsInstance.getPublicDnsName())

But cannot find out how to get the hostname - theres no getHostname() method.

3
  • Why do you want to know that exactly? The existing methods provide plenty of information Commented Dec 17, 2014 at 13:11
  • The default hostname is the internal ip seperated by - instead of . Don't understand your problem. Commented Dec 17, 2014 at 13:13
  • Did you checked InetAddress if you are running jvm there? Commented Dec 17, 2014 at 13:16

1 Answer 1

2

Was able to get the hostname indirectly via:

awsInstance.getPrivateDnsName().split("\\.")[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.