Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Get on-demand pricing only for required region (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgunapati committed Jan 31, 2020
1 parent eda8a86 commit 1e3763e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cloud_provider/aws/aws_bid_advisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
# https://aws.amazon.com/blogs/aws/new-aws-price-list-api/
# Info about reading the csv:
# http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/reading-an-offer.html
AWS_PRICING_URL = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.csv'
HOURLY_TERM_CODE = 'JRTCKXETXF'
RATE_CODE = '6YS6EN2CT7'

def aws_pricing_url(region):
"""
retruns URL per region, Using the Bulk API
"""
base_url = "https://pricing.us-east-1.amazonaws.com"
url = "{0}/offers/v1.0/aws/AmazonEC2/current/{1}/index.csv".format(base_url, region)
return url

# The pricing API provided above only uses long region names and not the short
# one (like us-west-2). And, there
# doesn't seem to be any API that maps the short names to the long names.
Expand Down Expand Up @@ -129,7 +136,7 @@ def parse_price_row(self, row):
@retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3)
def get_on_demand_pricing(self):
""" Issues the AWS api for getting on-demand pricing info. """
resp = requests.get(url=AWS_PRICING_URL, stream=True)
resp = requests.get(url=aws_pricing_url(self.bid_advisor.region), stream=True)
line_iterator = resp.iter_lines()
line = None
for line in line_iterator:
Expand Down

0 comments on commit 1e3763e

Please sign in to comment.