Skip to content

Commit 7438766

Browse files
committed
docs: add examples for shorthands in the parameter utility
1 parent 5fb929d commit 7438766

File tree

3 files changed

+112
-12
lines changed

3 files changed

+112
-12
lines changed

aws_lambda_powertools/utilities/parameters/dynamodb.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ class DynamoDBProvider(BaseProvider):
1616
"""
1717
Amazon DynamoDB Parameter Provider
1818
19+
Parameters
20+
----------
21+
table_name: str
22+
Name of the DynamoDB table that stores parameters
23+
key_attr: str, optional
24+
Hash key for the DynamoDB table
25+
value_attr: str, optional
26+
Attribute that contains the values in the DynamoDB table
27+
config: botocore.config.Config, optional
28+
Botocore configuration to pass during client initialization
29+
1930
Example
2031
-------
2132
**Retrieves a parameter value from a DynamoDB table**
@@ -111,7 +122,7 @@ def _get(self, name: str, **sdk_options) -> str:
111122
----------
112123
name: str
113124
Name of the parameter
114-
sdk_options: dict
125+
sdk_options: dict, optional
115126
Dictionary of options that will be passed to the get_item call
116127
"""
117128

@@ -128,9 +139,9 @@ def _get_multiple(self, path: str, sort_attr: str = "sk", **sdk_options) -> Dict
128139
----------
129140
path: str
130141
Path to retrieve the parameters
131-
sort_attr: str
142+
sort_attr: str, optional
132143
Name of the DynamoDB table sort key (defaults to 'sk')
133-
sdk_options: dict
144+
sdk_options: dict, optional
134145
Dictionary of options that will be passed to the query call
135146
"""
136147

aws_lambda_powertools/utilities/parameters/secrets.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class SecretsProvider(BaseProvider):
1515
"""
1616
AWS Secrets Manager Parameter Provider
1717
18+
Parameters
19+
----------
20+
config: botocore.config.Config, optional
21+
Botocore configuration to pass during client initialization
22+
1823
Example
1924
-------
2025
**Retrieves a parameter value from Secrets Manager**
@@ -79,13 +84,42 @@ def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:
7984
raise NotImplementedError()
8085

8186

82-
def get_secret(name: str, transform: Optional[str] = None, decrypt: bool = False) -> Union[str, dict, bytes]:
87+
def get_secret(name: str, transform: Optional[str] = None, **sdk_options) -> Union[str, dict, bytes]:
8388
"""
8489
Retrieve a parameter value from AWS Secrets Manager
90+
91+
Parameters
92+
----------
93+
name: str
94+
Name of the parameter
95+
transform: str, optional
96+
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
97+
sdk_options: dict, optional
98+
Dictionary of options that will be passed to the get_secret_value call
99+
100+
Example
101+
-------
102+
**Retrieves a secret***
103+
104+
>>> from aws_lambda_powertools.utilities.parameters import get_secret
105+
>>>
106+
>>> get_secret("my-secret")
107+
108+
**Retrieves a secret and transforms using a JSON deserializer***
109+
110+
>>> from aws_lambda_powertools.utilities.parameters import get_secret
111+
>>>
112+
>>> get_secret("my-secret", transform="json")
113+
114+
**Retrieves a secret and passes custom arguments to the SDK**
115+
116+
>>> from aws_lambda_powertools.utilities.parameters import get_secret
117+
>>>
118+
>>> get_secret("my-secret", VersionId="f658cac0-98a5-41d9-b993-8a76a7799194")
85119
"""
86120

87121
# Only create the provider if this function is called at least once
88122
if "secrets" not in DEFAULT_PROVIDERS:
89123
DEFAULT_PROVIDERS["secrets"] = SecretsProvider()
90124

91-
return DEFAULT_PROVIDERS["secrets"].get(name, transform=transform, decrypt=decrypt)
125+
return DEFAULT_PROVIDERS["secrets"].get(name, transform=transform, **sdk_options)

aws_lambda_powertools/utilities/parameters/ssm.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class SSMProvider(BaseProvider):
1515
"""
1616
AWS Systems Manager Parameter Store Provider
1717
18+
Parameters
19+
----------
20+
config: botocore.config.Config, optional
21+
Botocore configuration to pass during client initialization
22+
1823
Example
1924
-------
2025
**Retrieves a parameter value from Systems Manager Parameter Store**
@@ -71,9 +76,9 @@ def _get(self, name: str, decrypt: bool = False, **sdk_options) -> str:
7176
----------
7277
name: str
7378
Parameter name
74-
decrypt: bool
79+
decrypt: bool, optional
7580
If the parameter value should be decrypted
76-
sdk_options: dict
81+
sdk_options: dict, optional
7782
Dictionary of options that will be passed to the get_parameter call
7883
"""
7984

@@ -91,11 +96,11 @@ def _get_multiple(self, path: str, decrypt: bool = False, recursive: bool = Fals
9196
----------
9297
path: str
9398
Path to retrieve the parameters
94-
decrypt: bool
99+
decrypt: bool, optional
95100
If the parameter values should be decrypted
96-
recursive: bool
101+
recursive: bool, optional
97102
If this should retrieve the parameter values recursively or not
98-
sdk_options: dict
103+
sdk_options: dict, optional
99104
Dictionary of options that will be passed to the get_parameters_by_path call
100105
"""
101106

@@ -131,9 +136,32 @@ def _get_multiple(self, path: str, decrypt: bool = False, recursive: bool = Fals
131136
return retval
132137

133138

134-
def get_parameter(name: str, transform: Optional[str] = None) -> Union[str, list, dict, bytes]:
139+
def get_parameter(name: str, transform: Optional[str] = None, **sdk_options) -> Union[str, list, dict, bytes]:
135140
"""
136141
Retrieve a parameter value from AWS Systems Manager (SSM) Parameter Store
142+
143+
Parameters
144+
----------
145+
name: str
146+
Name of the parameter
147+
transform: str, optional
148+
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
149+
sdk_options: dict, optional
150+
Dictionary of options that will be passed to the get_secret_value call
151+
152+
Example
153+
-------
154+
**Retrieves a parameter value from Systems Manager Parameter Store**
155+
156+
>>> from aws_lambda_powertools.utilities.parameters import get_parameter
157+
>>>
158+
>>> get_parameter("/my/parameter")
159+
160+
**Retrieves a parameter value and decodes it using a Base64 decoder**
161+
162+
>>> from aws_lambda_powertools.utilities.parameters import get_parameter
163+
>>>
164+
>>> get_parameter("/my/parameter", transform='binary')
137165
"""
138166

139167
# Only create the provider if this function is called at least once
@@ -144,10 +172,37 @@ def get_parameter(name: str, transform: Optional[str] = None) -> Union[str, list
144172

145173

146174
def get_parameters(
147-
path: str, transform: Optional[str] = None, recursive: bool = False, decrypt: bool = False
175+
path: str, transform: Optional[str] = None, recursive: bool = False, decrypt: bool = False, **sdk_options
148176
) -> Union[Dict[str, str], Dict[str, dict], Dict[str, bytes]]:
149177
"""
150178
Retrieve multiple parameter values from AWS Systems Manager (SSM) Parameter Store
179+
180+
Parameters
181+
----------
182+
path: str
183+
Path to retrieve the parameters
184+
transform: str, optional
185+
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
186+
decrypt: bool, optional
187+
If the parameter values should be decrypted
188+
recursive: bool, optional
189+
If this should retrieve the parameter values recursively or not
190+
sdk_options: dict, optional
191+
Dictionary of options that will be passed to the get_parameters_by_path call
192+
193+
Example
194+
-------
195+
**Retrieves parameter values from Systems Manager Parameter Store**
196+
197+
>>> from aws_lambda_powertools.utilities.parameters import get_parameter
198+
>>>
199+
>>> get_parameters("/my/path/parameter")
200+
201+
**Retrieves parameter values and decodes them using a Base64 decoder**
202+
203+
>>> from aws_lambda_powertools.utilities.parameters import get_parameter
204+
>>>
205+
>>> get_parameters("/my/path/parameter", transform='binary')
151206
"""
152207

153208
# Only create the provider if this function is called at least once

0 commit comments

Comments
 (0)