Use instance ID of newly created instance for the rest of the examples
@@ -39,8 +39,6 @@ public class EC2Application {
public static void main(String[] args) {
- String yourInstanceId = "<you-instance>";
-
// 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()
