How to obtain the Public IP Address on EC2 launch instance request?
<p>I can't figure it out how I can do it:</p>

<pre><code>runInstancesRequest.withImageId("ami-53170b32")
                .withInstanceType("t2.micro")
                .withMinCount(1)
                .withMaxCount(1)
                .withKeyName("mac")
                .withSecurityGroupIds("sg-49025d2d");

RunInstancesResult runInstancesResult =
                amazonEC2Client.runInstances(runInstancesRequest);
</code></pre>

<p>So far everything works fine. Now I want to get the Public IP Address from the recently started instance. How can I do that?</p>

<p>I tried:</p>

<pre><code>runInstancesResult.getReservation().getInstances().get(0).getPublicIpAddress()
</code></pre>

<p>but the IP is always null.</p>