How to find the IP address of an amazon EC2 instance on reboot

前端 未结 10 1301
长发绾君心
长发绾君心 2020-12-12 13:50

On reboot, the IP address of an amazon instance changes. How to find the new IP address using java API?

10条回答
  •  一生所求
    2020-12-12 14:07

    you Can Use This.

                    var ipofnewServer = string.Empty;    
                    while (string.IsNullOrEmpty(ipofnewServer))
                    {
                        var statusRequest1 = new DescribeInstancesRequest
                        {
                            InstanceIds = new List() { instanceId }
                        };
    
                        var result = amazonEc2client.DescribeInstances(statusRequest1);
                        var status = result.Reservations[0].Instances.FirstOrDefault();
                        if (status != null)
                        {
                            ipofnewServer = status.PublicIpAddress;
                        }
                    }
    

提交回复
热议问题