While running "aws ec2 describe-instances" in command line, It gives list of all ec2 Instances but with Java AWS-SDK it's gives zero Reservations. Please see below code snippet,
AmazonEC2 ec2;
if (ec2 == null) {
AWSCredentialsProviderChain credentialsProvider = new
AWSCredentialsProviderChain(
new InstanceProfileCredentialsProvider(),
new ProfileCredentialsProvider("default"));
ec2 = new AmazonEC2Client(credentialsProvider);
}
for (Reservation reservation : ec2.describeInstances().getReservations()) {
for (Instance instance : reservation.getInstances()) {
System.out.println("TAG" + instance.getInstanceId());
}
}