我正在使用 aws java sdk 创建我的实例,我的函数看起来像这样
private static void createInstance()
throws AmazonServiceException, AmazonClientException, InterruptedException
{
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.withInstanceType("m1.small")
.withImageId("my_ami")
.withMinCount(1)
.withMaxCount(1)
.withKeyName("my_key")
;
RunInstancesResult runInstances = ec2.runInstances(runInstancesRequest);
}
并找到所有正在运行的实例的 IP 地址,如下所示:
public static ArrayList<String> findIPs(){
ArrayList<String> myArr = new ArrayList<String>();
DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
List<Reservation> reservations = describeInstancesRequest.getReservations();
Set<Instance> instances = new HashSet<Instance>();
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
if(reservation.getInstances().get(0).getPrivateIpAddress()!= null)
{
myArr.add(reservation.getInstances().get(0).getPrivateIpAddress());
}
}
return myArr;
}
我想知道最近创建的实例 ID 和 IP 地址。有人可以指导我如何找到最近创建的 AWS 实例的 ID 和 IP 地址。谢谢