Skip to content

Commit

Permalink
bug: aws sdk no longer accepts an empty NextToken
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Oct 20, 2023
1 parent d1eeaea commit fd183c6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/converged-computing/cloud-select/tree/main) (0.0.x)
- aws prices no longer works to receive an empty NextToken (0.0.22)
- fix one-off error for table listing (0.0.21)
- support for spot-instance example
- add aws price cache example and use non-deprecated oras upload_* functions (0.0.2)
Expand Down
20 changes: 15 additions & 5 deletions cloudselect/cloud/aws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,23 @@ def prices(self):

# Keep track of how many times we've tried
retries = 0
next_token = ""
next_token = None
prices = []

while True:
try:
response = self.pricing_cli.get_products(
ServiceCode="AmazonEC2", NextToken=next_token
)
# AWS (as of October 2023) no longer accepts an empty NextToken
# Max results default has also decreased, so we specify max
if not next_token:
response = self.pricing_cli.get_products(
ServiceCode="AmazonEC2", MaxResults=100
)
else:
response = self.pricing_cli.get_products(
ServiceCode="AmazonEC2",
NextToken=next_token,
MaxResults=100,
)
# Be generous and retry for any client error
except ClientError as err:
if "Rate exceeded" not in err.args[0] or retries > self.max_retries:
Expand All @@ -73,6 +83,7 @@ def prices(self):

if not response.get("NextToken"):
break

next_token = response.get("NextToken")
# The prices are actually string - so let's search region of interest via regex
for pricestr in response["PriceList"]:
Expand All @@ -81,7 +92,6 @@ def prices(self):
prices.append(json.loads(pricestr))
print(f"{len(prices)} total aws prices matching {regex}...", end="\r")
print()

return self.load_prices(prices)

def instances(self):
Expand Down
2 changes: 1 addition & 1 deletion cloudselect/cloud/aws/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class AmazonPrices(Prices):
"""
Google Compute Engine prices
AWS prices
"""

pass
4 changes: 2 additions & 2 deletions cloudselect/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ allow_missing_attributes: false

# cloud specific settings
google:
regions: ["us-east1", "us-west1", "us-central1"]
regions: [us-east1, us-west1, us-central1]

aws:
regions: ["us-east-1"]
regions: [us-east-1]
2 changes: 1 addition & 1 deletion cloudselect/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: (MIT)

__version__ = "0.0.21"
__version__ = "0.0.22"
AUTHOR = "Vanessa Sochat"
EMAIL = "[email protected]"
NAME = "cloud-select-tool"
Expand Down

0 comments on commit fd183c6

Please sign in to comment.