Skip to content

Commit c2d088e

Browse files
refactor(parameters): increase default max_age (cache) to 5 minutes (#4279)
1 parent 91c8584 commit c2d088e

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

aws_lambda_powertools/utilities/parameters/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from mypy_boto3_ssm import SSMClient
4040

4141

42-
DEFAULT_MAX_AGE_SECS = "5"
42+
DEFAULT_MAX_AGE_SECS = "300"
4343

4444
# These providers will be dynamically initialized on first use of the helper functions
4545
DEFAULT_PROVIDERS: Dict[str, Any] = {}

docs/utilities/parameters.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The parameters utility provides high-level functions to retrieve one or multiple
99
## Key features
1010

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

@@ -143,7 +143,7 @@ The following environment variables are available to configure the parameter uti
143143

144144
| Setting | Description | Environment variable | Default |
145145
|-----------------------|--------------------------------------------------------------------------------|-------------------------------------|---------|
146-
| **Max Age** | Adjusts for how long values are kept in cache (in seconds). | `POWERTOOLS_PARAMETERS_MAX_AGE` | `5` |
146+
| **Max Age** | Adjusts for how long values are kept in cache (in seconds). | `POWERTOOLS_PARAMETERS_MAX_AGE` | `300` |
147147
| **Debug Sample Rate** | Sets whether to decrypt or not values retrieved from AWS SSM Parameters Store. | `POWERTOOLS_PARAMETERS_SSM_DECRYPT` | `false` |
148148

149149
You can also use [`POWERTOOLS_PARAMETERS_MAX_AGE`](#adjusting-cache-ttl) through the `max_age` parameter and [`POWERTOOLS_PARAMETERS_SSM_DECRYPT`](#ssmprovider) through the `decrypt` parameter to override the environment variable values.
@@ -155,7 +155,7 @@ You can also use [`POWERTOOLS_PARAMETERS_MAX_AGE`](#adjusting-cache-ttl) through
155155
???+ tip
156156
`max_age` parameter is also available in underlying provider functions like `get()`, `get_multiple()`, etc.
157157

158-
By default, we cache parameters retrieved in-memory for 5 seconds. If you want to change this default value and set the same TTL for all parameters, you can set the `POWERTOOLS_PARAMETERS_MAX_AGE` environment variable. **You can still set `max_age` for individual parameters**.
158+
By default, we cache parameters retrieved in-memory for 300 seconds (5 minutes). If you want to change this default value and set the same TTL for all parameters, you can set the `POWERTOOLS_PARAMETERS_MAX_AGE` environment variable. **You can still set `max_age` for individual parameters**.
159159

160160
You can adjust how long we should keep values in cache by using the param `max_age`, when using `get_parameter()`, `get_parameters()` and `get_secret()` methods across all providers.
161161

@@ -446,8 +446,8 @@ Here is the mapping between this utility's functions and methods and the underly
446446
| SSM Parameter Store | `SSMProvider.get_multiple` | `ssm` | [get_parameters_by_path](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.get_parameters_by_path){target="_blank"} |
447447
| Secrets Manager | `get_secret` | `secretsmanager` | [get_secret_value](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.get_secret_value){target="_blank"} |
448448
| Secrets Manager | `SecretsProvider.get` | `secretsmanager` | [get_secret_value](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.get_secret_value){target="_blank"} |
449-
| DynamoDB | `DynamoDBProvider.get` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table){target="_blank"}) | [get_item](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.get_item) |
450-
| DynamoDB | `DynamoDBProvider.get_multiple` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table){target="_blank"}) | [query](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.query) |
449+
| DynamoDB | `DynamoDBProvider.get` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table){target="_blank"}) |
450+
| DynamoDB | `DynamoDBProvider.get_multiple` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table){target="_blank"}) |
451451
| App Config | `get_app_config` | `appconfigdata` | [start_configuration_session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata.html#AppConfigData.Client.start_configuration_session){target="_blank"} and [get_latest_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfigdata.html#AppConfigData.Client.get_latest_configuration){target="_blank"} |
452452

453453
### Bring your own boto client

tests/unit/data_classes/test_sqs_event.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ def test_sqs_dlq_trigger_event():
6565
assert attributes.sequence_number is None
6666
assert attributes.message_group_id is None
6767
assert attributes.message_deduplication_id is None
68-
assert (
69-
attributes.dead_letter_queue_source_arn
70-
== raw_attributes["DeadLetterQueueSourceArn"]
71-
)
68+
assert attributes.dead_letter_queue_source_arn == raw_attributes["DeadLetterQueueSourceArn"]
7269

7370

7471
def test_decode_nested_s3_event():

tests/unit/parser/test_sqs.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,4 @@ def test_sqs_dlq_trigger_event():
117117
convert_time = int(round(attributes.SentTimestamp.timestamp() * 1000))
118118
assert convert_time == int(raw_record["attributes"]["SentTimestamp"])
119119

120-
assert (
121-
attributes.DeadLetterQueueSourceArn
122-
== raw_record["attributes"]["DeadLetterQueueSourceArn"]
123-
)
120+
assert attributes.DeadLetterQueueSourceArn == raw_record["attributes"]["DeadLetterQueueSourceArn"]

0 commit comments

Comments
 (0)