Skip to content

Commit f4a7946

Browse files
author
orrym
committed
BAEL-1572: Use instance ID of newly created instance for the rest of the examples
1 parent 92bf897 commit f4a7946

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎aws/src/main/java/com/baeldung/ec2/EC2Application.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public class EC2Application {
3838
}
3939

4040
public static void main(String[] args) {
41-
42-
String yourInstanceId = "<you-instance>";
43-
41+
4442
// 0) - Set up the client
4543
AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard()
4644
.withCredentials(new AWSStaticCredentialsProvider(credentials))
@@ -91,7 +89,7 @@ public static void main(String[] args) {
9189
.withKeyName("baeldung-key-pair") // optional - if not present, can't connect to instance
9290
.withSecurityGroups("BaeldungSecurityGroup");
9391

94-
ec2Client.runInstances(runInstancesRequest);
92+
String yourInstanceId = ec2Client.runInstances(runInstancesRequest).getReservation().getInstances().get(0).getInstanceId();
9593

9694
// 6) Monitor Instances
9795
MonitorInstancesRequest monitorInstancesRequest = new MonitorInstancesRequest()

0 commit comments

Comments
 (0)