1
1
"""
2
2
AWS SSM Parameter retrieval and caching utility
3
3
"""
4
- import concurrent .futures
5
- import functools
6
- from concurrent .futures import Future
7
4
from typing import TYPE_CHECKING , Any , Dict , Optional , Union , overload
8
5
9
6
import boto3
@@ -356,7 +353,6 @@ def get_parameters_by_name(
356
353
decrypt : bool = False ,
357
354
force_fetch : bool = False ,
358
355
max_age : int = DEFAULT_MAX_AGE_SECS ,
359
- parallel : bool = False ,
360
356
) -> Dict [str , str ]:
361
357
...
362
358
@@ -368,7 +364,6 @@ def get_parameters_by_name(
368
364
decrypt : bool = False ,
369
365
force_fetch : bool = False ,
370
366
max_age : int = DEFAULT_MAX_AGE_SECS ,
371
- parallel : bool = False ,
372
367
) -> Dict [str , bytes ]:
373
368
...
374
369
@@ -380,7 +375,6 @@ def get_parameters_by_name(
380
375
decrypt : bool = False ,
381
376
force_fetch : bool = False ,
382
377
max_age : int = DEFAULT_MAX_AGE_SECS ,
383
- parallel : bool = False ,
384
378
) -> Dict [str , Dict [str , Any ]]:
385
379
...
386
380
@@ -392,7 +386,6 @@ def get_parameters_by_name(
392
386
decrypt : bool = False ,
393
387
force_fetch : bool = False ,
394
388
max_age : int = DEFAULT_MAX_AGE_SECS ,
395
- parallel : bool = False ,
396
389
) -> Union [Dict [str , str ], Dict [str , dict ]]:
397
390
...
398
391
@@ -403,7 +396,6 @@ def get_parameters_by_name(
403
396
decrypt : bool = False ,
404
397
force_fetch : bool = False ,
405
398
max_age : int = DEFAULT_MAX_AGE_SECS ,
406
- parallel : bool = False ,
407
399
) -> Union [Dict [str , str ], Dict [str , bytes ], Dict [str , dict ]]:
408
400
"""
409
401
Retrieve multiple parameter values by name from AWS Systems Manager (SSM) Parameter Store
@@ -420,8 +412,6 @@ def get_parameters_by_name(
420
412
Force update even before a cached item has expired, defaults to False
421
413
max_age: int
422
414
Maximum age of the cached value
423
- sdk_options: dict, optional
424
- Dictionary of options that will be passed to the Parameter Store get_parameter API call
425
415
426
416
Raises
427
417
------
@@ -432,54 +422,24 @@ def get_parameters_by_name(
432
422
When the parameter provider fails to transform a parameter value.
433
423
"""
434
424
435
- # NOTE: Need a param for hard failure mode on parameter retrieval (asked feature request author)
436
- # NOTE: Decide whether to leave multi-threaded option or not due to slower results (throttling+LWP cost)
425
+ # NOTE: Decided against using multi-thread due to single-thread outperforming in 128M and 1G + timeout risk
426
+ # see: https://github.com/awslabs/aws-lambda-powertools-python/issues/1040#issuecomment-1299954613
437
427
438
428
ret : Dict [str , Any ] = {}
439
- future_to_param : Dict [Future , str ] = {}
440
-
441
- if parallel :
442
- with concurrent .futures .ThreadPoolExecutor (max_workers = len (parameters )) as pool :
443
- for parameter , options in parameters .items ():
444
- if isinstance (options , dict ):
445
- transform = options .get ("transform" ) or transform
446
- decrypt = options .get ("decrypt" ) or decrypt
447
- max_age = options .get ("max_age" ) or max_age
448
- force_fetch = options .get ("force_fetch" ) or force_fetch
449
-
450
- fetch_parameter_callable = functools .partial (
451
- get_parameter ,
452
- name = parameter ,
453
- transform = transform ,
454
- decrypt = decrypt ,
455
- max_age = max_age ,
456
- force_fetch = force_fetch ,
457
- )
458
-
459
- future = pool .submit (fetch_parameter_callable )
460
- future_to_param [future ] = parameter
461
-
462
- for future in concurrent .futures .as_completed (future_to_param ):
463
- try :
464
- # "parameter": "future result"
465
- ret [future_to_param [future ]] = future .result ()
466
- except Exception as exc :
467
- print (f"Uh oh, failed to fetch '{ future_to_param [future ]} ': { exc } " )
468
-
469
- else :
470
- for parameter , options in parameters .items ():
471
- if isinstance (options , dict ):
472
- transform = options .get ("transform" ) or transform
473
- decrypt = options .get ("decrypt" ) or decrypt
474
- max_age = options .get ("max_age" ) or max_age
475
- force_fetch = options .get ("force_fetch" ) or force_fetch
476
-
477
- ret [parameter ] = get_parameter (
478
- name = parameter ,
479
- transform = transform ,
480
- decrypt = decrypt ,
481
- max_age = max_age ,
482
- force_fetch = force_fetch ,
483
- )
429
+
430
+ for parameter , options in parameters .items ():
431
+ if isinstance (options , dict ):
432
+ transform = options .get ("transform" ) or transform
433
+ decrypt = options .get ("decrypt" ) or decrypt
434
+ max_age = options .get ("max_age" ) or max_age
435
+ force_fetch = options .get ("force_fetch" ) or force_fetch
436
+
437
+ ret [parameter ] = get_parameter (
438
+ name = parameter ,
439
+ transform = transform ,
440
+ decrypt = decrypt ,
441
+ max_age = max_age ,
442
+ force_fetch = force_fetch ,
443
+ )
484
444
485
445
return ret
0 commit comments