From f4a7946634dc70faa2d5d8c2ad52f22bc88947e1 Mon Sep 17 00:00:00 2001 From: orrym Date: Mon, 5 Mar 2018 20:48:37 +0200 Subject: [PATCH] BAEL-1572: Use instance ID of newly created instance for the rest of the examples --- aws/src/main/java/com/baeldung/ec2/EC2Application.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/aws/src/main/java/com/baeldung/ec2/EC2Application.java b/aws/src/main/java/com/baeldung/ec2/EC2Application.java index 62179145f9..6876eb7369 100644 --- a/aws/src/main/java/com/baeldung/ec2/EC2Application.java +++ b/aws/src/main/java/com/baeldung/ec2/EC2Application.java @@ -38,9 +38,7 @@ public class EC2Application { } public static void main(String[] args) { - - String yourInstanceId = ""; - + // 0) - Set up the client AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) @@ -91,7 +89,7 @@ public class EC2Application { .withKeyName("baeldung-key-pair") // optional - if not present, can't connect to instance .withSecurityGroups("BaeldungSecurityGroup"); - ec2Client.runInstances(runInstancesRequest); + String yourInstanceId = ec2Client.runInstances(runInstancesRequest).getReservation().getInstances().get(0).getInstanceId(); // 6) Monitor Instances MonitorInstancesRequest monitorInstancesRequest = new MonitorInstancesRequest()