12
12
13
13
from aws_lambda_powertools .shared import constants
14
14
from aws_lambda_powertools .shared .functions import (
15
+ resolve_max_age ,
15
16
resolve_truthy_env_var_choice ,
16
17
slice_dictionary ,
17
18
)
@@ -115,7 +116,7 @@ def __init__(
115
116
def get ( # type: ignore[override]
116
117
self ,
117
118
name : str ,
118
- max_age : int = DEFAULT_MAX_AGE_SECS ,
119
+ max_age : Optional [ int ] = None ,
119
120
transform : TransformOptions = None ,
120
121
decrypt : Optional [bool ] = None ,
121
122
force_fetch : bool = False ,
@@ -150,7 +151,10 @@ def get( # type: ignore[override]
150
151
When the parameter provider fails to transform a parameter value.
151
152
"""
152
153
153
- # Resolving if will use the value passed by parameter or the environment
154
+ # Resolving if will use the default value (5), the value passed by parameter or the environment variable
155
+ max_age = resolve_max_age (env = os .getenv (constants .PARAMETERS_MAX_AGE , DEFAULT_MAX_AGE_SECS ), choice = max_age )
156
+
157
+ # Resolving if will use the default value (False), the value passed by parameter or the environment variable
154
158
decrypt = resolve_truthy_env_var_choice (
155
159
env = os .getenv (constants .PARAMETERS_DEFAULT_DECRYPT , "false" ), choice = decrypt
156
160
)
@@ -223,7 +227,7 @@ def get_parameters_by_name(
223
227
parameters : Dict [str , Dict ],
224
228
transform : TransformOptions = None ,
225
229
decrypt : Optional [bool ] = None ,
226
- max_age : int = DEFAULT_MAX_AGE_SECS ,
230
+ max_age : Optional [ int ] = None ,
227
231
raise_on_error : bool = True ,
228
232
) -> Dict [str , str ] | Dict [str , bytes ] | Dict [str , dict ]:
229
233
"""
@@ -270,6 +274,9 @@ def get_parameters_by_name(
270
274
When "_errors" reserved key is in parameters to be fetched from SSM.
271
275
"""
272
276
277
+ # Resolving if will use the default value (5), the value passed by parameter or the environment variable
278
+ max_age = resolve_max_age (env = os .getenv (constants .PARAMETERS_MAX_AGE , DEFAULT_MAX_AGE_SECS ), choice = max_age )
279
+
273
280
# Resolving if will use the default value (False), the value passed by parameter or the environment variable
274
281
decrypt = resolve_truthy_env_var_choice (
275
282
env = os .getenv (constants .PARAMETERS_DEFAULT_DECRYPT , "false" ), choice = decrypt
@@ -505,7 +512,7 @@ def get_parameter(
505
512
transform : Optional [str ] = None ,
506
513
decrypt : Optional [bool ] = None ,
507
514
force_fetch : bool = False ,
508
- max_age : int = DEFAULT_MAX_AGE_SECS ,
515
+ max_age : Optional [ int ] = None ,
509
516
** sdk_options ,
510
517
) -> Union [str , dict , bytes ]:
511
518
"""
@@ -559,6 +566,9 @@ def get_parameter(
559
566
if "ssm" not in DEFAULT_PROVIDERS :
560
567
DEFAULT_PROVIDERS ["ssm" ] = SSMProvider ()
561
568
569
+ # Resolving if will use the default value (5), the value passed by parameter or the environment variable
570
+ max_age = resolve_max_age (env = os .getenv (constants .PARAMETERS_MAX_AGE , DEFAULT_MAX_AGE_SECS ), choice = max_age )
571
+
562
572
# Resolving if will use the default value (False), the value passed by parameter or the environment variable
563
573
decrypt = resolve_truthy_env_var_choice (
564
574
env = os .getenv (constants .PARAMETERS_DEFAULT_DECRYPT , "false" ), choice = decrypt
@@ -578,7 +588,7 @@ def get_parameters(
578
588
recursive : bool = True ,
579
589
decrypt : Optional [bool ] = None ,
580
590
force_fetch : bool = False ,
581
- max_age : int = DEFAULT_MAX_AGE_SECS ,
591
+ max_age : Optional [ int ] = None ,
582
592
raise_on_transform_error : bool = False ,
583
593
** sdk_options ,
584
594
) -> Union [Dict [str , str ], Dict [str , dict ], Dict [str , bytes ]]:
@@ -638,6 +648,9 @@ def get_parameters(
638
648
if "ssm" not in DEFAULT_PROVIDERS :
639
649
DEFAULT_PROVIDERS ["ssm" ] = SSMProvider ()
640
650
651
+ # Resolving if will use the default value (5), the value passed by parameter or the environment variable
652
+ max_age = resolve_max_age (env = os .getenv (constants .PARAMETERS_MAX_AGE , DEFAULT_MAX_AGE_SECS ), choice = max_age )
653
+
641
654
# Resolving if will use the default value (False), the value passed by parameter or the environment variable
642
655
decrypt = resolve_truthy_env_var_choice (
643
656
env = os .getenv (constants .PARAMETERS_DEFAULT_DECRYPT , "false" ), choice = decrypt
@@ -661,7 +674,7 @@ def get_parameters_by_name(
661
674
parameters : Dict [str , Dict ],
662
675
transform : None = None ,
663
676
decrypt : Optional [bool ] = None ,
664
- max_age : int = DEFAULT_MAX_AGE_SECS ,
677
+ max_age : Optional [ int ] = None ,
665
678
raise_on_error : bool = True ,
666
679
) -> Dict [str , str ]:
667
680
...
@@ -672,7 +685,7 @@ def get_parameters_by_name(
672
685
parameters : Dict [str , Dict ],
673
686
transform : Literal ["binary" ],
674
687
decrypt : Optional [bool ] = None ,
675
- max_age : int = DEFAULT_MAX_AGE_SECS ,
688
+ max_age : Optional [ int ] = None ,
676
689
raise_on_error : bool = True ,
677
690
) -> Dict [str , bytes ]:
678
691
...
@@ -683,7 +696,7 @@ def get_parameters_by_name(
683
696
parameters : Dict [str , Dict ],
684
697
transform : Literal ["json" ],
685
698
decrypt : Optional [bool ] = None ,
686
- max_age : int = DEFAULT_MAX_AGE_SECS ,
699
+ max_age : Optional [ int ] = None ,
687
700
raise_on_error : bool = True ,
688
701
) -> Dict [str , Dict [str , Any ]]:
689
702
...
@@ -694,7 +707,7 @@ def get_parameters_by_name(
694
707
parameters : Dict [str , Dict ],
695
708
transform : Literal ["auto" ],
696
709
decrypt : Optional [bool ] = None ,
697
- max_age : int = DEFAULT_MAX_AGE_SECS ,
710
+ max_age : Optional [ int ] = None ,
698
711
raise_on_error : bool = True ,
699
712
) -> Union [Dict [str , str ], Dict [str , dict ]]:
700
713
...
@@ -704,7 +717,7 @@ def get_parameters_by_name(
704
717
parameters : Dict [str , Any ],
705
718
transform : TransformOptions = None ,
706
719
decrypt : Optional [bool ] = None ,
707
- max_age : int = DEFAULT_MAX_AGE_SECS ,
720
+ max_age : Optional [ int ] = None ,
708
721
raise_on_error : bool = True ,
709
722
) -> Union [Dict [str , str ], Dict [str , bytes ], Dict [str , dict ]]:
710
723
"""
@@ -758,6 +771,9 @@ def get_parameters_by_name(
758
771
# NOTE: Decided against using multi-thread due to single-thread outperforming in 128M and 1G + timeout risk
759
772
# see: https://github.com/awslabs/aws-lambda-powertools-python/issues/1040#issuecomment-1299954613
760
773
774
+ # Resolving if will use the default value (5), the value passed by parameter or the environment variable
775
+ max_age = resolve_max_age (env = os .getenv (constants .PARAMETERS_MAX_AGE , DEFAULT_MAX_AGE_SECS ), choice = max_age )
776
+
761
777
# Resolving if will use the default value (False), the value passed by parameter or the environment variable
762
778
decrypt = resolve_truthy_env_var_choice (
763
779
env = os .getenv (constants .PARAMETERS_DEFAULT_DECRYPT , "false" ), choice = decrypt
0 commit comments