无法获得现货价格历史记录的最大结果-美国东部地区 [英] Can't get max result of spot price history - US-EAST region

查看:72
本文介绍了无法获得现货价格历史记录的最大结果-美国东部地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检索"us-east-f1"或"us-east-1"中任何区域的现货历史价格时,结果始终小于200价格,我需要单个区域和单个实例类型. 如何获取大量结果? 例如:

When I retrieve the history price of spot for "us-east-f1" or any region in "us-east-1", the result always less than 200 price, I need for single region and single instance type. How can I retrieve a huge number of results? EX:

ec2 = boto3.client('ec2')
t=datetime.datetime.now() - datetime.timedelta(0)
f=datetime.datetime.now() - datetime.timedelta(90)
response= ec2.describe_spot_price_history(InstanceTypes =['c3.4xlarge'],ProductDescriptions = ['Linux/UNIX'], AvailabilityZone = 'us-east-1a', StartTime= f, EndTime = t, MaxResults=1000)
response =response['SpotPriceHistory']

我的意思是对于单个区域和实例类型,我需要最大结果大于此值.

I mean for a single region and instance type, I need the max result to be larger than this.

我使用分页器获取所有可用页面的所有结果:

I use paginator to get all result for all available pages:

paginator = ec2.get_paginator('describe_spot_price_history') 
page_iterator = paginator.paginate(StartTime= t, EndTime = f, MaxResults=2000 ) 
for page in page_iterator: 
   output = page['SpotPriceHistory'] 

但是,我仍然得到相同数量的结果!当我获取90天的结果时,我仍然得到相同数量的结果吗? 如何获得所有结果或获得最大价格值?

However, I still get the same number of results! When I fetch the results of 90 days, I still got have the same amount of results? How to get all results or to get the max amount of price values?

推荐答案

您的代码似乎运行良好,但是开始和结束时间戳记是向后的.

Your code appears to be working just fine, but the start and end timestamps were backwards.

我运行了这段代码:

import boto3
import datetime

start_date = datetime.datetime.now() - datetime.timedelta(90)
end_date = datetime.datetime.now() - datetime.timedelta(0)

ec2 = boto3.client('ec2', region_name='us-east-1')
paginator = ec2.get_paginator('describe_spot_price_history') 
page_iterator = paginator.paginate(InstanceTypes =['c3.4xlarge'],ProductDescriptions = ['Linux/UNIX'], AvailabilityZone = 'us-east-1a', StartTime= start_date, EndTime = end_date, MaxResults=2000 ) 

for page in page_iterator: 
   print page['SpotPriceHistory'] 

我回到一页,有122个条目.

I got back one page that had 122 entries.

第一个条目是在2018-04-01:

The first entry was for 2018-04-01:

{u'Timestamp': datetime.datetime(2018,
    4,
    1,
    4,
    40,
    44, tzinfo=tzutc()), u'AvailabilityZone': 'us-east-1a', u'InstanceType': 'c3.4xlarge', u'ProductDescription': 'Linux/UNIX', u'SpotPrice': '0.840000'
},

最后输入是2018年1月2日:

The last entry was for 2018-01-02:

{u'Timestamp': datetime.datetime(2018,
    1,
    2,
    0,
    28,
    35, tzinfo=tzutc()), u'AvailabilityZone': 'us-east-1a', u'InstanceType': 'c3.4xlarge', u'ProductDescription': 'Linux/UNIX', u'SpotPrice': '0.840000'
}

这涵盖了最多90天的可用数据.

This cover the maximum 90 days of data that is available.

这篇关于无法获得现货价格历史记录的最大结果-美国东部地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆