From fd183c665fb8295b49c00301f1e5d7b293916089 Mon Sep 17 00:00:00 2001 From: vsoch Date: Thu, 19 Oct 2023 22:09:06 -0600 Subject: [PATCH] bug: aws sdk no longer accepts an empty NextToken Signed-off-by: vsoch --- CHANGELOG.md | 1 + cloudselect/cloud/aws/client.py | 20 +++++++++++++++----- cloudselect/cloud/aws/prices.py | 2 +- cloudselect/settings.yml | 4 ++-- cloudselect/version.py | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e31c75e..3df934e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cloudselect/cloud/aws/client.py b/cloudselect/cloud/aws/client.py index c2a6a70..8a51d6b 100644 --- a/cloudselect/cloud/aws/client.py +++ b/cloudselect/cloud/aws/client.py @@ -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: @@ -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"]: @@ -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): diff --git a/cloudselect/cloud/aws/prices.py b/cloudselect/cloud/aws/prices.py index 33a4866..5441ad5 100644 --- a/cloudselect/cloud/aws/prices.py +++ b/cloudselect/cloud/aws/prices.py @@ -8,7 +8,7 @@ class AmazonPrices(Prices): """ - Google Compute Engine prices + AWS prices """ pass diff --git a/cloudselect/settings.yml b/cloudselect/settings.yml index 87dae17..4adedfd 100644 --- a/cloudselect/settings.yml +++ b/cloudselect/settings.yml @@ -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] diff --git a/cloudselect/version.py b/cloudselect/version.py index f1e5fdc..1a95c72 100644 --- a/cloudselect/version.py +++ b/cloudselect/version.py @@ -3,7 +3,7 @@ # # SPDX-License-Identifier: (MIT) -__version__ = "0.0.21" +__version__ = "0.0.22" AUTHOR = "Vanessa Sochat" EMAIL = "vsoch@users.noreply.github.com" NAME = "cloud-select-tool"