60
60
config = Config (retries = {"max_attempts" : 10 })
61
61
client = session .client ("pricing" , region_name = "us-east-1" , config = config )
62
62
63
+ _UNSUPPORTED_REGIONS = set ()
64
+
63
65
64
66
def configure_logging ():
65
67
"""Setup Logging"""
@@ -94,13 +96,15 @@ def get_dax_pricing():
94
96
product = products .get ("product" , {})
95
97
if product :
96
98
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 (
104
108
product .get ("attributes" ).get ("usagetype" ).split (":" )[1 ]
105
109
)
106
110
return results
@@ -115,18 +119,18 @@ def get_mq_pricing():
115
119
product = products .get ("product" , {})
116
120
if product :
117
121
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 ()
124
130
usage_type = (
125
131
product .get ("attributes" ).get ("usagetype" ).split (":" )[1 ]
126
132
)
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 ))
130
134
return results
131
135
132
136
@@ -170,22 +174,19 @@ def get_rds_pricing():
170
174
if product .get ("attributes" ).get ("locationType" ) == "AWS Outposts" :
171
175
continue
172
176
# 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" ) )
182
186
# Rds Instance Size spec
183
187
product_names = product_map .get (
184
188
product .get ("attributes" ).get ("engineCode" ), []
185
189
)
186
- product_region = region_map .get (
187
- product .get ("attributes" ).get ("location" )
188
- )
189
190
license_name = license_map .get (
190
191
product .get ("attributes" ).get ("licenseModel" )
191
192
)
@@ -202,20 +203,18 @@ def get_rds_pricing():
202
203
203
204
instance_type = product .get ("attributes" ).get ("instanceType" )
204
205
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 ] = {}
209
210
if (
210
- not rds_details .get (product_region )
211
+ not rds_details .get (location )
211
212
.get (deployment_option )
212
213
.get (license_name )
213
214
):
214
- rds_details [product_region ][deployment_option ][
215
- license_name
216
- ] = {}
215
+ rds_details [location ][deployment_option ][license_name ] = {}
217
216
if (
218
- not rds_details .get (product_region )
217
+ not rds_details .get (location )
219
218
.get (deployment_option )
220
219
.get (license_name )
221
220
.get (product_name )
@@ -225,14 +224,14 @@ def get_rds_pricing():
225
224
and product_name
226
225
in ["aurora-mysql" , "aurora-postgresql" ]
227
226
):
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" ])
231
230
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 ][
236
235
product_name
237
236
].add (instance_type )
238
237
specs = {}
@@ -350,21 +349,15 @@ def get_results(service, product_families, default=None):
350
349
product .get ("productFamily" ) in product_families
351
350
and product .get ("attributes" ).get ("locationType" ) == "AWS Region"
352
351
):
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" )
357
356
)
358
357
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" ))
368
361
return results
369
362
370
363
@@ -441,6 +434,9 @@ def main():
441
434
get_results ("AmazonAppStream" , ["Streaming Instance" ]),
442
435
)
443
436
437
+ for region in _UNSUPPORTED_REGIONS :
438
+ LOGGER .warning (f"Region { region !r} is not supported" )
439
+
444
440
445
441
if __name__ == "__main__" :
446
442
try :
0 commit comments