Skip to content

Commit e38b9cc

Browse files
authored
update scripts to have better region support (#3910)
1 parent 03e1857 commit e38b9cc

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

scripts/update_specs_from_pricing.py

+53-57
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
config = Config(retries={"max_attempts": 10})
6161
client = session.client("pricing", region_name="us-east-1", config=config)
6262

63+
_UNSUPPORTED_REGIONS = set()
64+
6365

6466
def configure_logging():
6567
"""Setup Logging"""
@@ -94,13 +96,15 @@ def get_dax_pricing():
9496
product = products.get("product", {})
9597
if product:
9698
if product.get("productFamily") in ["DAX"]:
97-
if not results.get(
98-
region_map[product.get("attributes").get("location")]
99-
):
100-
results[
101-
region_map[product.get("attributes").get("location")]
102-
] = set()
103-
results[region_map[product.get("attributes").get("location")]].add(
99+
location = region_map.get(product.get("attributes").get("location"))
100+
if not location:
101+
_UNSUPPORTED_REGIONS.add(
102+
product.get("attributes").get("location")
103+
)
104+
continue
105+
if not results.get(location):
106+
results[location] = set()
107+
results[location].add(
104108
product.get("attributes").get("usagetype").split(":")[1]
105109
)
106110
return results
@@ -115,18 +119,18 @@ def get_mq_pricing():
115119
product = products.get("product", {})
116120
if product:
117121
if product.get("productFamily") in ["Broker Instances"]:
118-
if not results.get(
119-
region_map[product.get("attributes").get("location")]
120-
):
121-
results[
122-
region_map[product.get("attributes").get("location")]
123-
] = set()
122+
location = region_map.get(product.get("attributes").get("location"))
123+
if not location:
124+
_UNSUPPORTED_REGIONS.add(
125+
product.get("attributes").get("location")
126+
)
127+
continue
128+
if not results.get(location):
129+
results[location] = set()
124130
usage_type = (
125131
product.get("attributes").get("usagetype").split(":")[1]
126132
)
127-
results[region_map[product.get("attributes").get("location")]].add(
128-
remap.get(usage_type, usage_type)
129-
)
133+
results[location].add(remap.get(usage_type, usage_type))
130134
return results
131135

132136

@@ -170,22 +174,19 @@ def get_rds_pricing():
170174
if product.get("attributes").get("locationType") == "AWS Outposts":
171175
continue
172176
# Get overall instance types
173-
if not results.get(
174-
region_map[product.get("attributes").get("location")]
175-
):
176-
results[
177-
region_map[product.get("attributes").get("location")]
178-
] = set(["db.serverless"])
179-
results[region_map[product.get("attributes").get("location")]].add(
180-
product.get("attributes").get("instanceType")
181-
)
177+
location = region_map.get(product.get("attributes").get("location"))
178+
if not location:
179+
_UNSUPPORTED_REGIONS.add(
180+
product.get("attributes").get("location")
181+
)
182+
continue
183+
if not results.get(location):
184+
results[location] = set(["db.serverless"])
185+
results[location].add(product.get("attributes").get("instanceType"))
182186
# Rds Instance Size spec
183187
product_names = product_map.get(
184188
product.get("attributes").get("engineCode"), []
185189
)
186-
product_region = region_map.get(
187-
product.get("attributes").get("location")
188-
)
189190
license_name = license_map.get(
190191
product.get("attributes").get("licenseModel")
191192
)
@@ -202,20 +203,18 @@ def get_rds_pricing():
202203

203204
instance_type = product.get("attributes").get("instanceType")
204205
for product_name in product_names:
205-
if not rds_details.get(product_region):
206-
rds_details[product_region] = {}
207-
if not rds_details.get(product_region).get(deployment_option):
208-
rds_details[product_region][deployment_option] = {}
206+
if not rds_details.get(location):
207+
rds_details[location] = {}
208+
if not rds_details.get(location).get(deployment_option):
209+
rds_details[location][deployment_option] = {}
209210
if (
210-
not rds_details.get(product_region)
211+
not rds_details.get(location)
211212
.get(deployment_option)
212213
.get(license_name)
213214
):
214-
rds_details[product_region][deployment_option][
215-
license_name
216-
] = {}
215+
rds_details[location][deployment_option][license_name] = {}
217216
if (
218-
not rds_details.get(product_region)
217+
not rds_details.get(location)
219218
.get(deployment_option)
220219
.get(license_name)
221220
.get(product_name)
@@ -225,14 +224,14 @@ def get_rds_pricing():
225224
and product_name
226225
in ["aurora-mysql", "aurora-postgresql"]
227226
):
228-
rds_details[product_region][deployment_option][
229-
license_name
230-
][product_name] = set(["db.serverless"])
227+
rds_details[location][deployment_option][license_name][
228+
product_name
229+
] = set(["db.serverless"])
231230
else:
232-
rds_details[product_region][deployment_option][
233-
license_name
234-
][product_name] = set()
235-
rds_details[product_region][deployment_option][license_name][
231+
rds_details[location][deployment_option][license_name][
232+
product_name
233+
] = set()
234+
rds_details[location][deployment_option][license_name][
236235
product_name
237236
].add(instance_type)
238237
specs = {}
@@ -350,21 +349,15 @@ def get_results(service, product_families, default=None):
350349
product.get("productFamily") in product_families
351350
and product.get("attributes").get("locationType") == "AWS Region"
352351
):
353-
if product.get("attributes").get("location") not in region_map:
354-
LOGGER.warning(
355-
'Region "%s" not found',
356-
product.get("attributes").get("location"),
352+
location = region_map.get(product.get("attributes").get("location"))
353+
if not location:
354+
_UNSUPPORTED_REGIONS.add(
355+
product.get("attributes").get("location")
357356
)
358357
continue
359-
if not results.get(
360-
region_map[product.get("attributes").get("location")]
361-
):
362-
results[
363-
region_map[product.get("attributes").get("location")]
364-
] = default
365-
results[region_map[product.get("attributes").get("location")]].add(
366-
product.get("attributes").get("instanceType")
367-
)
358+
if not results.get(location):
359+
results[location] = default
360+
results[location].add(product.get("attributes").get("instanceType"))
368361
return results
369362

370363

@@ -441,6 +434,9 @@ def main():
441434
get_results("AmazonAppStream", ["Streaming Instance"]),
442435
)
443436

437+
for region in _UNSUPPORTED_REGIONS:
438+
LOGGER.warning(f"Region {region!r} is not supported")
439+
444440

445441
if __name__ == "__main__":
446442
try:

0 commit comments

Comments
 (0)