22from pathlib import Path
33from typing import Any , Dict , Optional , Union
44
5+ import boto3
56from pydantic import BaseSettings
67
7- from .ssm import lazy_parameter
8-
98logger = logging .getLogger (__name__ )
109
1110
@@ -15,12 +14,16 @@ class AwsSsmSettingsSource:
1514 def __init__ (self , ssm_prefix : Union [Path , str , None ]):
1615 self .ssm_prefix : Union [Path , str , None ] = ssm_prefix
1716
17+ @property
18+ def client (self ):
19+ return boto3 .client ("ssm" )
20+
1821 def __call__ (self , settings : BaseSettings ) -> Dict [str , Any ]:
1922 """
2023 Returns lazy SSM values for all settings.
2124 """
2225 secrets : Dict [str , Optional [Any ]] = {}
23-
26+
2427 if self .ssm_prefix is None :
2528 return secrets
2629
@@ -31,10 +34,11 @@ def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
3134
3235 logger .debug (f"Building SSM settings with prefix of { secrets_path = } " )
3336
34- for field in settings .__fields__ .values ():
35- for env_name in field .field_info .extra ["env_names" ]:
36- secrets [field .alias ] = lazy_parameter (path = (secrets_path / env_name ), field = field )
37- return secrets
37+ params = self .client .get_parameters_by_path (Path = str (secrets_path ), WithDecryption = True )['Parameters' ]
38+
39+ return {
40+ str (Path (param ['Name' ]).relative_to (secrets_path )): param ['Value' ] for param in params
41+ }
3842
3943 def __repr__ (self ) -> str :
4044 return f"AwsSsmSettingsSource(ssm_prefix={ self .ssm_prefix !r} )"
0 commit comments