亚马逊现货价格历史记录-Java代码

亚马逊现货价格历史记录-Java代码,java,sdk,amazon-ec2,Java,Sdk,Amazon Ec2,应该可以获得过去90天的AWS现货价格历史记录。当使用JavaSDK时,可以创建一个查询来获取一些历史记录,但是因为这个列表太长,所以他们将其拆分。使用令牌,您应该能够获得列表的下一部分,直到您收到整个列表 问题是,使用给定的令牌,我还无法检索到比列表的第一部分更多的内容。在搜索互联网时,很明显我对这个代币的理解是正确的 // Create the AmazonEC2Client object so we can call various APIs. AmazonEC2 ec2

应该可以获得过去90天的AWS现货价格历史记录。当使用JavaSDK时,可以创建一个查询来获取一些历史记录,但是因为这个列表太长,所以他们将其拆分。使用令牌,您应该能够获得列表的下一部分,直到您收到整个列表

问题是,使用给定的令牌,我还无法检索到比列表的第一部分更多的内容。在搜索互联网时,很明显我对这个代币的理解是正确的

    // Create the AmazonEC2Client object so we can call various APIs.
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);

    // Get the spot price history
    DescribeSpotPriceHistoryResult result = ec2.describeSpotPriceHistory();

    // Print first part of list
    for (int i = 0; i < result.getSpotPriceHistory().size(); i++) {
        System.out.println(result.getSpotPriceHistory().get(i));
    }

    result = result.withNextToken(result.getNextToken());

    // Print second part of list
    for (int i = 0; i < result.getSpotPriceHistory().size(); i++) {
            System.out.println(result.getSpotPriceHistory().get(i));
    }
//创建AmazonEC2Client对象,以便调用各种API。
AmazonEC2 ec2=新的AmazonEC2客户端(凭据);
//获取现货价格历史记录
DescribeSpotPriceHistoryResult=ec2.describeSpotPriceHistory();
//打印列表的第一部分
for(int i=0;i
结果的“nextToken”不变。知道我做错了什么吗?SDK中有bug吗?我通过Eclipse安装了它


提前谢谢

您确实没有按预期使用API-您需要使用从中检索的
nextToken
重新提交API(当然,您也可以在后者上设置
nextToken
,这有点让人困惑,我猜这最好只是一个内部方法),例如:

//创建AmazonEC2Client对象,以便调用各种API。
AmazonEC2 ec2=新的AmazonEC2客户端(凭据);
//获取现货价格历史记录
字符串nextToken=“”;
做{
//准备请求(包括nextToken,如果以前的结果可用)
DescribeSpotPriceHistoryRequest=新的DescribeSpotPriceHistoryRequest()
.使用nextToken(nextToken);
//执行请求
descrippeSpotPriceHistoryResult=ec2
.描述历史记录(请求);
for(int i=0;i
// Create the AmazonEC2Client object so we can call various APIs.
AmazonEC2 ec2 = new AmazonEC2Client(credentials);

// Get the spot price history
String nextToken = "";
do {
    // Prepare request (include nextToken if available from previous result)
    DescribeSpotPriceHistoryRequest request = new DescribeSpotPriceHistoryRequest()
            .withNextToken(nextToken);

    // Perform request
    DescribeSpotPriceHistoryResult result = ec2
            .describeSpotPriceHistory(request);
    for (int i = 0; i < result.getSpotPriceHistory().size(); i++) {
        System.out.println(result.getSpotPriceHistory().get(i));
    }

    // 'nextToken' is the string marking the next set of results returned (if any), 
    // it will be empty if there are no more results to be returned.            
    nextToken = result.getNextToken();

} while (!nextToken.isEmpty());