Skip to content

Commit 2bde5ad

Browse files
committed
docs(parameters): refresh to use new navigation
1 parent d597740 commit 2bde5ad

File tree

1 file changed

+108
-100
lines changed

1 file changed

+108
-100
lines changed

docs/utilities/parameters.md

Lines changed: 108 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ description: Utility
44
---
55

66

7-
The parameters utility provides a way to retrieve parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) or [Amazon DynamoDB](https://aws.amazon.com/dynamodb/). It also provides a base class to create your parameter provider implementation.
7+
The parameters utility provides high-level functions to retrieve one or multiple parameter values from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html){target="_blank"}, [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/), [AWS AppConfig](https://aws.amazon.com/appconfig/){target="_blank"}, [Amazon DynamoDB](https://aws.amazon.com/dynamodb/){target="_blank"}, or bring your own.
88

9-
**Key features**
9+
## Key features
1010

1111
* Retrieve one or multiple parameters from the underlying provider
1212
* Cache parameter values for a given amount of time (defaults to 5 seconds)
1313
* Transform parameter values from JSON or base 64 encoded strings
14+
* Bring Your Own Parameter Store Provider
1415

15-
**IAM Permissions**
16+
## Getting started
1617

17-
This utility requires additional permissions to work as expected. See the table below:
18+
By default, we fetch parameters from System Manager Parameter Store, secrets from Secrets Manager, and application configuration from AppConfig.
19+
20+
### IAM Permissions
21+
22+
This utility requires additional permissions to work as expected.
23+
24+
!!! note "Different parameter providers require different permissions"
1825

1926
Provider | Function/Method | IAM Permission
2027
------------------------------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------
@@ -25,13 +32,15 @@ DynamoDB | `DynamoDBProvider.get` | `dynamodb:GetItem`
2532
DynamoDB | `DynamoDBProvider.get_multiple` | `dynamodb:Query`
2633
App Config | `AppConfigProvider.get_app_config`, `get_app_config` | `appconfig:GetConfiguration`
2734

28-
## SSM Parameter Store
35+
### Fetching parameters
2936

30-
You can retrieve a single parameter using `get_parameter` high-level function. For multiple parameters, you can use `get_parameters` and pass a path to retrieve them recursively.
37+
You can retrieve a single parameter using `get_parameter` high-level function.
38+
39+
For multiple parameters, you can use `get_parameters` and pass a path to retrieve them recursively.
3140

3241
=== "ssm_parameter_store.py"
3342

34-
```python
43+
```python hl_lines="1 5 9"
3544
from aws_lambda_powertools.utilities import parameters
3645

3746
def handler(event, context):
@@ -45,15 +54,51 @@ You can retrieve a single parameter using `get_parameter` high-level function. F
4554
print(f"{k}: {v}")
4655
```
4756

48-
### SSMProvider class
57+
### Fetching secrets
58+
59+
You can fetch secrets stored in Secrets Manager using `get_secrets`.
60+
61+
=== "secrets_manager.py"
62+
63+
```python hl_lines="1 5"
64+
from aws_lambda_powertools.utilities import parameters
65+
66+
def handler(event, context):
67+
# Retrieve a single secret
68+
value = parameters.get_secret("my-secret")
69+
```
70+
71+
### Fetching app configurations
72+
73+
> New in 1.10.0
4974
50-
Alternatively, you can use the `SSMProvider` class, which gives more flexibility, such as the ability to configure the underlying SDK client.
75+
You can fetch application configurations in AWS AppConfig using `get_app_config`.
5176

52-
This can be used to retrieve values from other regions, change the retry behavior, etc.
77+
The following will retrieve the latest version and store it in the cache.
78+
79+
=== "appconfig.py"
80+
81+
```python hl_lines="1 5"
82+
from aws_lambda_powertools.utilities import parameters
83+
84+
def handler(event, context):
85+
# Retrieve a single configuration, latest version
86+
value: bytes = parameters.get_app_config(name="my_configuration", environment="my_env", application="my_app")
87+
```
88+
89+
## Advanced
90+
91+
### Built-in provider class
92+
93+
For greater flexibility such as configuring the underlying SDK client used by built-in providers, you can use their respective Provider Classes directly.
94+
95+
!!! tip "This can be used to retrieve values from other regions, change the retry behavior, etc."
96+
97+
#### SSMProvider
5398

5499
=== "ssm_parameter_store.py"
55100

56-
```python
101+
```python hl_lines="5 9 12"
57102
from aws_lambda_powertools.utilities import parameters
58103
from botocore.config import Config
59104

@@ -70,20 +115,18 @@ This can be used to retrieve values from other regions, change the retry behavio
70115
print(f"{k}: {v}")
71116
```
72117

73-
**Additional arguments**
74-
75118
The AWS Systems Manager Parameter Store provider supports two additional arguments for the `get()` and `get_multiple()` methods:
76119

77120
| Parameter | Default | Description |
78121
|---------------|---------|-------------|
79122
| **decrypt** | `False` | Will automatically decrypt the parameter. |
80123
| **recursive** | `True` | For `get_multiple()` only, will fetch all parameter values recursively based on a path prefix. |
81124

82-
**Example:**
125+
> **Example**
83126
84127
=== "ssm_parameter_store.py"
85128

86-
```python
129+
```python hl_lines="6 8"
87130
from aws_lambda_powertools.utilities import parameters
88131

89132
ssm_provider = parameters.SSMProvider()
@@ -94,29 +137,11 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen
94137
no_recursive_values = ssm_provider.get_multiple("/my/path/prefix", recursive=False)
95138
```
96139

97-
## Secrets Manager
98-
99-
For secrets stored in Secrets Manager, use `get_secret`.
140+
#### SecretsProvider
100141

101142
=== "secrets_manager.py"
102143

103-
```python
104-
from aws_lambda_powertools.utilities import parameters
105-
106-
def handler(event, context):
107-
# Retrieve a single secret
108-
value = parameters.get_secret("my-secret")
109-
```
110-
111-
### SecretsProvider class
112-
113-
Alternatively, you can use the `SecretsProvider` class, which give more flexibility, such as the ability to configure the underlying SDK client.
114-
115-
This can be used to retrieve values from other regions, change the retry behavior, etc.
116-
117-
=== "secrets_manager.py"
118-
119-
```python
144+
```python hl_lines="5 9"
120145
from aws_lambda_powertools.utilities import parameters
121146
from botocore.config import Config
122147

@@ -128,25 +153,24 @@ This can be used to retrieve values from other regions, change the retry behavio
128153
value = secrets_provider.get("my-secret")
129154
```
130155

131-
## DynamoDB
132-
133-
To use the DynamoDB provider, you need to import and instantiate the `DynamoDBProvider` class.
156+
#### DynamoDBProvider
134157

135158
The DynamoDB Provider does not have any high-level functions, as it needs to know the name of the DynamoDB table containing the parameters.
136159

137-
**DynamoDB table structure**
160+
**DynamoDB table structure for single parameters**
138161

139-
When using the default options, if you want to retrieve only single parameters, your table should be structured as such, assuming a parameter named **my-parameter** with a value of **my-value**. The `id` attribute should be the [partition key](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey) for that table.
162+
For single parameters, you must use `id` as the [partition key](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey) for that table.
140163

141164
| id | value |
142165
|--------------|----------|
143166
| my-parameter | my-value |
144167

145-
With this table, when you do a `dynamodb_provider.get("my-param")` call, this will return `my-value`.
168+
> **Example**
146169
147-
=== "dynamodb.py"
170+
=== "app.py"
171+
With this table, the return value of `dynamodb_provider.get("my-param")` call will be `my-value`.
148172

149-
```python
173+
```python hl_lines="3 7"
150174
from aws_lambda_powertools.utilities import parameters
151175

152176
dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table")
@@ -156,31 +180,34 @@ With this table, when you do a `dynamodb_provider.get("my-param")` call, this wi
156180
value = dynamodb_provider.get("my-parameter")
157181
```
158182

159-
**Retrieve multiple values**
183+
**DynamoDB table structure for multiple values parameters**
184+
185+
If you want to be able to retrieve multiple parameters at once sharing the same `id`, your table needs to contain a sort key name `sk`.
160186

161-
If you want to be able to retrieve multiple parameters at once sharing the same `id`, your table needs to contain a sort key name `sk`. For example, if you want to retrieve multiple parameters having `my-hash-key` as ID:
187+
For example, if you want to retrieve multiple parameters having `my-hash-key` as ID:
162188

163189
| id | sk | value |
164190
|-------------|---------|------------|
165191
| my-hash-key | param-a | my-value-a |
166192
| my-hash-key | param-b | my-value-b |
167193
| my-hash-key | param-c | my-value-c |
168194

169-
With this table, when you do a `dynamodb_provider.get_multiple("my-hash-key")` call, you will receive the following dict as a response:
170195

171-
```
196+
With this table, the return of `dynamodb_provider.get_multiple("my-hash-key")` call will be a dictionary like:
197+
198+
```json
172199
{
173200
"param-a": "my-value-a",
174201
"param-b": "my-value-b",
175202
"param-c": "my-value-c"
176203
}
177204
```
178205

179-
**Example:**
206+
> **Example**
180207
181-
=== "dynamodb_multiple.py"
208+
=== "app_multiple_parameters.py"
182209

183-
```python
210+
```python hl_lines="3 8"
184211
from aws_lambda_powertools.utilities import parameters
185212

186213
dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table")
@@ -195,7 +222,7 @@ With this table, when you do a `dynamodb_provider.get_multiple("my-hash-key")` c
195222

196223
**Additional arguments**
197224

198-
The Amazon DynamoDB provider supports four additional arguments at initialization:
225+
The DynamoDB provider supports four additional arguments at initialization. These can be used if you require a custom table structure:
199226

200227
| Parameter | Mandatory | Default | Description |
201228
|----------------|-----------|---------|-------------|
@@ -204,9 +231,11 @@ The Amazon DynamoDB provider supports four additional arguments at initializatio
204231
| **sort_attr** | No | `sk` | Range key for the DynamoDB table. You don't need to set this if you don't use the `get_multiple()` method.
205232
| **value_attr** | No | `value` | Name of the attribute containing the parameter value.
206233

207-
=== "dynamodb.py"
234+
> **Example**
235+
236+
=== "app.py"
208237

209-
```python
238+
```python hl_lines="3-8"
210239
from aws_lambda_powertools.utilities import parameters
211240

212241
dynamodb_provider = parameters.DynamoDBProvider(
@@ -220,32 +249,11 @@ The Amazon DynamoDB provider supports four additional arguments at initializatio
220249
value = dynamodb_provider.get("my-parameter")
221250
```
222251

223-
## App Config
224-
225-
> New in 1.10.0
226-
227-
For configurations stored in App Config, use `get_app_config`.
228-
The following will retrieve the latest version and store it in the cache.
229-
230-
=== "appconfig.py"
231-
232-
```python
233-
from aws_lambda_powertools.utilities import parameters
234-
235-
def handler(event, context):
236-
# Retrieve a single configuration, latest version
237-
value: bytes = parameters.get_app_config(name="my_configuration", environment="my_env", application="my_app")
238-
```
239-
240-
### AppConfigProvider class
241-
242-
Alternatively, you can use the `AppConfigProvider` class, which give more flexibility, such as the ability to configure the underlying SDK client.
252+
#### AppConfigProvider
243253

244-
This can be used to retrieve values from other regions, change the retry behavior, etc.
254+
=== "app.py"
245255

246-
=== "appconfig.py"
247-
248-
```python
256+
```python hl_lines="5 9"
249257
from aws_lambda_powertools.utilities import parameters
250258
from botocore.config import Config
251259

@@ -257,7 +265,7 @@ This can be used to retrieve values from other regions, change the retry behavio
257265
value: bytes = appconf_provider.get("my_conf")
258266
```
259267

260-
## Create your own provider
268+
### Create your own provider
261269

262270
You can create your own custom parameter store provider by inheriting the `BaseProvider` class, and implementing both `_get()` and `_get_multiple()` methods to retrieve a single, or multiple parameters from your custom store.
263271

@@ -267,7 +275,7 @@ Here is an example implementation using S3 as a custom parameter store:
267275

268276
=== "custom_provider.py"
269277

270-
```python
278+
```python hl_lines="3 6 17 27"
271279
import copy
272280

273281
from aws_lambda_powertools.utilities import BaseProvider
@@ -321,13 +329,24 @@ Here is an example implementation using S3 as a custom parameter store:
321329

322330
```
323331

324-
## Transform values
332+
### Deserializing values with transform parameter
333+
334+
For parameters stored in JSON or Base64 format, you can use the `transform` argument for deserialization.
325335

326-
For parameters stored in JSON or Base64 format, you can use the `transform` argument for deserialization - The `transform` argument is available across all providers, including the high level functions.
336+
!!! info "The `transform` argument is available across all providers, including the high level functions"
327337

328-
=== "transform.py"
338+
=== "High level functions"
329339

330-
```python
340+
```python hl_lines="4"
341+
from aws_lambda_powertools.utilities import parameters
342+
343+
def handler(event, context):
344+
value_from_json = parameters.get_parameter("/my/json/parameter", transform="json")
345+
```
346+
347+
=== "Providers"
348+
349+
```python hl_lines="7 10"
331350
from aws_lambda_powertools.utilities import parameters
332351

333352
ssm_provider = parameters.SSMProvider()
@@ -340,28 +359,17 @@ For parameters stored in JSON or Base64 format, you can use the `transform` argu
340359
value_from_binary = ssm_provider.get("/my/binary/parameter", transform="binary")
341360
```
342361

343-
You can also use the `transform` argument with high-level functions:
344-
345-
=== "transform.py"
346-
347-
```python
348-
from aws_lambda_powertools.utilities import parameters
349-
350-
def handler(event, context):
351-
value_from_json = parameters.get_parameter("/my/json/parameter", transform="json")
352-
```
353-
354-
### Partial transform failures with `get_multiple()`
362+
#### Partial transform failures with `get_multiple()`
355363

356364
If you use `transform` with `get_multiple()`, you can have a single malformed parameter value. To prevent failing the entire request, the method will return a `None` value for the parameters that failed to transform.
357365

358-
You can override this by setting the `raise_on_transform_error` argument to `True`. If you do so, a single transform error will raise a `TransformParameterError` exception.
366+
You can override this by setting the `raise_on_transform_error` argument to `True`. If you do so, a single transform error will raise a **`TransformParameterError`** exception.
359367

360-
For example, if you have three parameters (*/param/a*, */param/b* and */param/c*) but */param/c* is malformed:
368+
For example, if you have three parameters, */param/a*, */param/b* and */param/c*, but */param/c* is malformed:
361369

362370
=== "partial_failures.py"
363371

364-
```python
372+
```python hl_lines="9 14-15"
365373
from aws_lambda_powertools.utilities import parameters
366374

367375
ssm_provider = parameters.SSMProvider()
@@ -379,13 +387,13 @@ For example, if you have three parameters (*/param/a*, */param/b* and */param/c*
379387
values = ssm_provider.get_multiple("/param", transform="json", raise_on_transform_error=True)
380388
```
381389

382-
## Additional SDK arguments
390+
### Passing additional SDK arguments
383391

384392
You can use arbitrary keyword arguments to pass it directly to the underlying SDK method.
385393

386394
=== "ssm_parameter_store.py"
387395

388-
```python
396+
```python hl_lines="7"
389397
from aws_lambda_powertools.utilities import parameters
390398

391399
secrets_provider = parameters.SecretsProvider()

0 commit comments

Comments
 (0)