Can't get max result of spot price history - US-EAST region

ぐ巨炮叔叔 提交于 2019-12-13 03:46:29

问题


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.

Edit:

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'] 

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?


回答1:


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

I ran this code:

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'] 

I got back one page that had 122 entries.

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'
},

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'
}

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




回答2:


To make an API call to another region, specify the region_name:

ec2 = boto3.client('ec2', region_name='ap-southeast-2')

When MaxResults is exceeded, obtain the next set of results by making the same call, but set NextToken to the value returned by NextToken in the previous result set.



来源:https://stackoverflow.com/questions/49400385/cant-get-max-result-of-spot-price-history-us-east-region

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!