我是 Android 新手,但我之前已经使用过 AWS SDK for PHP,而且我从来没有遇到过这种问题。我正在使用 DescribeInstancesRequest 获取所有实例及其状态的列表。想法是使用 ToggleButton 列出所有实例以进行启动/停止操作。通过 AsyncTask 我正在执行对 AWS 的请求,如下所示:
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);
}
}
事情是我在响应实例列表中只获得了 1 个 EC2 实例,而不是我目前使用的全部 4 个。任何人都有类似的问题或知道从 AWS SDK 获取实例列表的另一种方法?
我将不胜感激 - 谢谢。