java代码价格_亚马逊现货价格历史 – Java代码

应该可以获得过去90天的AWS Spot Price历史记录.使用

Java SDK时,可以创建一个查询来获取一些历史记录,但由于此列表太长,因此将它拆分.使用令牌,您应该能够获得列表的下一部分,直到您收到整个列表为止.

问题是使用给定的令牌我还不能检索更多的列表的第一部分.在搜索互联网时,很明显我对这个标记的理解是正确的.

// 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));

}

结果的“nextToken”没有改变.我有什么想法我做错了吗? SDK中是否有错误?我是通过Eclipse安装的.

提前致谢!

最佳答案 您确实没有按预期使用API​​ – 您需要使用从

DescribeSpotPriceHistoryResult检索到的nextToken重新提交

DescribeSpotPriceHistoryRequest(不可否认,您可以在后者上设置nextToken有点令人困惑,猜测它理想情况下应该只是一个内部方法) ,例如:

// 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());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值