Method used to get InstanceID in CreateInstance.java example is incorrect
While trying to play around with the example(CreateInstance.java) snippets, I noticed that below is used to get instanceID:-
String instance_id = run_response.getReservation().getReservationId();
This is incorrect, as this gives the reservation ID of the format "r-" and correct way to get Instance ID is actually this:-
run_response.getReservation().getInstances();
Provided solution by psuri seems to not work anymore. It seems that this code does not give instance ID but reservation ID. I was able to get instance ID using this:
String instance_id = response.instances().get(0).instanceId();
However there are still issues with creating TAG
The request must contain the parameter resourceIdSet (Service: Ec2, Status Code: 400, Request ID: 224a76bc-7da9-4639-b2df-63f0d0ec7764)
Tagging problem also solved.
CreateTagsRequest tag_request = CreateTagsRequest.builder()
.resources(instance_id)
.tags(tag)
.build();
Sample has been updated.