Secrets
AWS Secrets Manager parameter retrieval and caching utility
CLASS | DESCRIPTION |
---|---|
SecretsProvider |
AWS Secrets Manager Parameter Provider |
FUNCTION | DESCRIPTION |
---|---|
get_secret |
Retrieve a parameter value from AWS Secrets Manager |
set_secret |
Modify the details of a secret or create a new secret if it doesn't already exist. |
SecretsProvider ¶
SecretsProvider(
config: Config | None = None,
boto_config: Config | None = None,
boto3_session: boto3.session.Session | None = None,
boto3_client: SecretsManagerClient | None = None,
)
Bases: BaseProvider
AWS Secrets Manager Parameter Provider
PARAMETER | DESCRIPTION | ||
---|---|---|---|
config
|
Botocore configuration to pass during client initialization
TYPE:
|
||
boto3_session
|
TYPE:
|
||
boto3_client
|
TYPE:
|
Example
Retrieves a parameter value from Secrets Manager
1 2 3 4 5 6 7 |
|
Retrieves a parameter value from Secrets Manager in another AWS region
1 2 3 4 5 6 7 8 9 10 |
|
Retrieves a parameter value from Secrets Manager passing options to the SDK call
1 2 3 4 5 6 7 |
|
METHOD | DESCRIPTION |
---|---|
set |
Modify the details of a secret or create a new secret if it doesn't already exist. |
Source code in aws_lambda_powertools/utilities/parameters/secrets.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
set ¶
set(
name: str,
value: str | bytes | dict,
*,
client_request_token: str | None = None,
**sdk_options
) -> CreateSecretResponseTypeDef
Modify the details of a secret or create a new secret if it doesn't already exist.
We aim to minimize API calls by assuming that the secret already exists and needs updating. If it doesn't exist, we attempt to create a new one. Refer to the following workflow for a better understanding:
1 2 3 4 5 6 |
|
βββββββββββββββββββ βββββββββββββββββββββββ βUpdate Secret APIββββββββββββββββββββββββββββββββββββββββββββββΆβ Return or Exception β βββββββββββββββββββ βββββββββββββββββββββββ
PARAMETER | DESCRIPTION |
---|---|
name
|
The ARN or name of the secret to add a new version to or create a new one.
TYPE:
|
value
|
Specifies text data that you want to encrypt and store in this new version of the secret. |
client_request_token
|
This value helps ensure idempotency. It's recommended that you generate a UUID-type value to ensure uniqueness within the specified secret. This value becomes the VersionId of the new version. This field is auto-populated if not provided, but no idempotency will be enforced this way.
TYPE:
|
sdk_options
|
Dictionary of options that will be passed to the Secrets Manager update_secret API call
DEFAULT:
|
RAISES | DESCRIPTION |
---|---|
SetSecretError
|
When attempting to update or create a secret fails. |
Example
Sets a secret*
1 2 3 |
|
Sets a secret and includes an client_request_token
1 2 3 4 5 6 7 8 |
|
1 2 |
|
Source code in aws_lambda_powertools/utilities/parameters/secrets.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
get_secret ¶
get_secret(
name: str,
transform: None = None,
force_fetch: bool = False,
max_age: int | None = None,
**sdk_options
) -> str
get_secret(
name: str,
transform: Literal["json"],
force_fetch: bool = False,
max_age: int | None = None,
**sdk_options
) -> dict
get_secret(
name: str,
transform: Literal["binary"],
force_fetch: bool = False,
max_age: int | None = None,
**sdk_options
) -> str | bytes | dict
get_secret(
name: str,
transform: Literal["auto"],
force_fetch: bool = False,
max_age: int | None = None,
**sdk_options
) -> bytes
get_secret(
name: str,
transform: TransformOptions = None,
force_fetch: bool = False,
max_age: int | None = None,
**sdk_options
) -> str | bytes | dict
Retrieve a parameter value from AWS Secrets Manager
PARAMETER | DESCRIPTION |
---|---|
name
|
Name of the parameter
TYPE:
|
transform
|
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
TYPE:
|
force_fetch
|
Force update even before a cached item has expired, defaults to False
TYPE:
|
max_age
|
Maximum age of the cached value
TYPE:
|
sdk_options
|
Dictionary of options that will be passed to the get_secret_value call
DEFAULT:
|
RAISES | DESCRIPTION |
---|---|
GetParameterError
|
When the parameter provider fails to retrieve a parameter value for a given name. |
TransformParameterError
|
When the parameter provider fails to transform a parameter value. |
Example
Retrieves a secret*
1 2 3 |
|
Retrieves a secret and transforms using a JSON deserializer*
1 2 3 |
|
Retrieves a secret and passes custom arguments to the SDK
1 2 3 |
|
Source code in aws_lambda_powertools/utilities/parameters/secrets.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
set_secret ¶
set_secret(
name: str,
value: str | bytes,
*,
client_request_token: str | None = None,
**sdk_options
) -> CreateSecretResponseTypeDef
Modify the details of a secret or create a new secret if it doesn't already exist.
We aim to minimize API calls by assuming that the secret already exists and needs updating. If it doesn't exist, we attempt to create a new one. Refer to the following workflow for a better understanding:
1 2 3 4 5 6 |
|
βββββββββββββββββββ βββββββββββββββββββββββ βUpdate Secret APIββββββββββββββββββββββββββββββββββββββββββββββΆβ Return or Exception β βββββββββββββββββββ βββββββββββββββββββββββ
PARAMETER | DESCRIPTION |
---|---|
name
|
The ARN or name of the secret to add a new version to or create a new one.
TYPE:
|
value
|
Specifies text data that you want to encrypt and store in this new version of the secret. |
client_request_token
|
This value helps ensure idempotency. It's recommended that you generate a UUID-type value to ensure uniqueness within the specified secret. This value becomes the VersionId of the new version. This field is auto-populated if not provided, but no idempotency will be enforced this way.
TYPE:
|
sdk_options
|
Dictionary of options that will be passed to the Secrets Manager update_secret API call
DEFAULT:
|
RAISES | DESCRIPTION |
---|---|
SetSecretError
|
When attempting to update or create a secret fails. |
Example
Sets a secret*
1 2 3 |
|
Sets a secret and includes an client_request_token
1 2 3 4 5 6 7 |
|
1 2 |
|
Source code in aws_lambda_powertools/utilities/parameters/secrets.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|