Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in OpenSearch scraper #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ def scrape(output_file, input_file=None):

# loop through products, and only fetch available instances for now
for sku, product in tqdm(six.iteritems(data["products"])):
if (
product.get("productFamily", None) == "Amazon OpenSearch Service Instance"
if (product.get("productFamily", None) == "Amazon OpenSearch Service Instance"
and product.get("attributes", {}).get("operation", None)
!= "DirectQueryAmazonS3GDCOCU"
):
attributes = product["attributes"]
!= "DirectQueryAmazonS3GDCOCU"):

attributes = product.get("attributes", {})
if "instanceType" not in attributes:
continue

instance_type = attributes["instanceType"]

# map the region
location = ec2.canonicalize_location(attributes["location"])
instance_type = attributes["instanceType"]
if location == "Any":
region = "us-east-1"
elif location == "Asia Pacific (Osaka-Local)":
Expand All @@ -149,9 +151,7 @@ def scrape(output_file, input_file=None):

if instance_type not in instances.keys():
# delete some attributes that are inconsistent among skus
new_attributes = (
attributes.copy()
) # make copy so we can keep these attributes with the sku
new_attributes = attributes.copy() # make copy so we can keep these attributes with the sku
new_attributes.pop("location", None)
new_attributes.pop("locationType", None)
new_attributes.pop("operation", None)
Expand Down Expand Up @@ -291,9 +291,7 @@ def scrape(output_file, input_file=None):
"yrTerm3.noUpfront-hrs"
]

instances[instance_type]["pricing"][region][
"reserved"
] = reserved_prices
instances[instance_type]["pricing"][region]["reserved"] = reserved_prices
except Exception as e:
print(
"ERROR: Trouble generating Cache reserved price for {}: {!r}".format(
Expand All @@ -316,4 +314,4 @@ def scrape(output_file, input_file=None):
input_file = sys.argv[1]

output_file = "./www/opensearch/instances.json"
scrape(output_file, input_file)
scrape(output_file, input_file)
Loading