Bug: set_parameter and set_secret do not invalidate the cached value
Expected Behaviour
After set_parameter("/a", "new") or set_secret("s", "new") on a provider that had /a or s cached, the next get returns the new value.
Current Behaviour
SSMProvider.set (ssm.py:363) and SecretsProvider.set never touch self.store, so get keeps returning the old value for up to max_age seconds from the same provider instance (the module-level default provider in the high-level functions). The docs do not warn about this.
Code snippet
from botocore.config import Config
from botocore.stub import Stubber
from aws_lambda_powertools.utilities.parameters import SSMProvider
provider = SSMProvider(boto_config=Config(region_name="us-east-1"))
stub = Stubber(provider.client)
stub.add_response("get_parameter", {"Parameter": {"Name": "/a", "Value": "old", "Type": "String", "Version": 1}}, {"Name": "/a", "WithDecryption": False})
stub.add_response("put_parameter", {"Version": 2, "Tier": "Standard"}, None)
stub.activate()
provider.get("/a") # 'old'
provider.set("/a", "new", overwrite=True)
print(provider.get("/a")) # 'old' served from cache
Possible Solution
After a successful write, remove every store entry whose key starts with the parameter name (all transforms), in both providers.
Steps to Reproduce
Run the snippet above (it uses botocore.stub.Stubber, no AWS access needed).
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
[!WARNING] This issue is ready to be picked up, by humans or by agents. If you want it, comment here first so we can assign it to you, and please take only one or two issues at a time so others can join in too. The reproduction above runs locally without AWS access. Thanks!
Hi! I'd like to work on this issue as a second open-source contribution. I've already expressed interest in issue #8594, and I plan to keep my work limited to these two issues.
I'll investigate cache invalidation after successful parameter and secret writes and propose a focused fix with regression tests.
Could you please confirm that this issue is available and that the proposed scope is appropriate before I proceed? Thank you!
Hey @Suraj1347 pls go ahead.
[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
This is now released under 3.39.0 version!