user4078915
user4078915

Reputation:

Get hostname of AWS instance via Java API

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.

Upvotes: 2

Views: 2015

Answers (1)

user4078915
user4078915

Reputation:

Was able to get the hostname indirectly via:

awsInstance.getPrivateDnsName().split("\\.")[0]

Upvotes: 2

Related Questions