-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Parameters: add support for manual value refresh (WIP) #131
Comments
@nmoutschen @heitorlessa would this be via some kind of exception handler that picks up when the credentials failed? |
@nmoutschen a version of this is in this PR : #341 UX might be better for a decorator. |
@nmoutschen could you expand on what you meant with this feature request so we can get it added in Wednesday's release? Do you mean a parameter like what @michaelbrewer implemented on a per If it's the former, @michaelbrewer I'd suggest a more explicit name like |
Hey @michaelbrewer & @heitorlessa! I didn't have a specific implementation in mind and thought of 2 possibilities: pass a flag to the From a name point of view, |
Thanks @nmoutschen that makes sense. |
@heitorlessa i have made the changes just thinking of a good example for the docs, here it was i have so far: import os
from aws_lambda_powertools.utilities import parameters
class InvalidCredentials(Exception):
"""Raised when client get an invalid credentials error"""
class Client:
password = None
def configure(self, password):
self.password = password
def read_record(self):
"""Might raise an InvalidCredentials exception """
DB_PASS_PARAM = os.environ["DB_PASS_PARAM"]
db_client = Client()
db_client.configure(parameters.get_parameter(DB_PASS_PARAM))
def refresh_db_password():
db_client.configure(parameters.get_parameter(DB_PASS_PARAM, force_fetch=True))
def read_record(is_retry=False):
try:
return db_client.read_record()
except InvalidCredentials:
if not is_retry: # avoid infinite recursion
refresh_db_password() # force parameter refresh
return read_record(is_retry=True)
def handler(event, context):
return {"record": read_record()} |
This is now available in 1.12.0 :) Thanks @michaelbrewer ! https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.12.0 |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
This would add a method to the parameter provider to force-refresh a parameter value. This could be done through a flag.
Use cases: username/password that have expired and need to be refreshed.
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: