简体   繁体   中英

Android AWS SDK returning only one EC2 Instance instead of a list

I'm new to Android but I've already used AWS SDK for PHP previously and I never had this kind of a problem. I'm using DescribeInstancesRequest to fetch a list of all instances and their statuses. Idea is to have a list of all instances with ToggleButton for start/stop operations. Over AsyncTask I'm executing request to AWS like this:

private class LoadInstancesListTask extends AsyncTask<DescribeInstancesRequest, Void, DescribeInstancesResult> {

    private Context ctx;

    public void setContext(Context ctx) {
        this.ctx = ctx;
    }

    @Override
    protected DescribeInstancesResult doInBackground(DescribeInstancesRequest... params) {
        DescribeInstancesRequest request = params[0];
        AmazonEC2AsyncClient client = new AmazonEC2AsyncClient(request.getRequestCredentials());
        client.setEndpoint("ec2.us-east-1.amazonaws.com");
        DescribeInstancesResult response = client.describeInstances(request);
        return response;
    }

    @Override
    protected void onPostExecute(DescribeInstancesResult response) {
        Reservation reservation = response.getReservations().get(0);
        Log.d(MainActivity.TAG, reservation.toString());
        InstanceListAdapter adapter = new InstanceListAdapter(this.ctx, R.layout.instance_list_row_layout, reservation.getInstances());
        setListAdapter(adapter);
    }
}

Thing is I'm getting only 1 EC2 instance in response instance list instead of all 4 I'm currently using. Anyone had similar problem or know another way of fetching a list of instances from AWS SDK?

I'll appreciate any help - thanks.

As @chrkad pointed in the comment I was looking only to the first reservation instead processing all of them. Thanks again :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM