Skip to content
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

Bug: parameters confusing is combining get_parameter and get_parameters results #2438

Closed
beck3905 opened this issue Jun 12, 2023 · 11 comments · Fixed by #2839
Closed

Bug: parameters confusing is combining get_parameter and get_parameters results #2438

beck3905 opened this issue Jun 12, 2023 · 11 comments · Fixed by #2839
Assignees
Labels
bug Something isn't working parameters Parameters utility

Comments

@beck3905
Copy link

Expected Behaviour

Given SSM parameters:

  • /foo/bar/param1
  • /foo/bar/param2
  • /foo/bar/param3

Calling parameters.get_parameters("/foo/bar") should return a dictionary of all 3 parameters.
Calling parameters.get_parameter("/foo/bar") should ALWAYS raise a GetParameterError. This error should be raised even if the get_parameter call comes after the get_parameters call.

Current Behaviour

Given the same parameters as above:

If I call parameters.get_parameters("/foo/bar") all 3 parameters are cached under the parameter /foo/bar and returned as a dictionary.
If I subsequently call parameters.get_parameter("/foo/bar") it returns the same dictionary as the get_parameters call instead of raising the GetParameterError.

Code snippet

# Update paths below to PATH of actual SSM parameters in your account and not parameter NAMES.


from aws_lambda_powertools.utilities import parameters

print(parameters.get_parameters(path="/foo/bar"))
print(parameters.get_parameter("/foo/bar"))

Possible Solution

  • Cache get_parameter results separately from get_parameters results.
  • Note in the cache whether the values being cached are from get_parameter or get_parameters.

Steps to Reproduce

  1. Add multiple SSM parameters to parameter store under the same path.
  2. Run Code Snippet above referencing the SSM parameters' path.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.9

Packaging format used

Lambda Layers

Debugging logs

No response

@beck3905 beck3905 added bug Something isn't working triage Pending triage from maintainers labels Jun 12, 2023
@rubenfonseca
Copy link
Contributor

Looking at this now

@rubenfonseca
Copy link
Contributor

I have a couple of ideas, and will follow up tomorrow morning

@rubenfonseca
Copy link
Contributor

@beck3905 I'm looking at this again, and I'm wondering what's the use case that requires you to use both get_parameters and get_parameter with the same key. Can you expand a little on what are you trying to achieve? I need to understand the problem a little bit better in order to help the best way possible :)

@rubenfonseca rubenfonseca self-assigned this Jun 15, 2023
@rubenfonseca rubenfonseca added triage Pending triage from maintainers need-customer-feedback Requires more customers feedback before making or revisiting a decision and removed triage Pending triage from maintainers labels Jun 15, 2023
@beck3905
Copy link
Author

beck3905 commented Jun 15, 2023

@beck3905 I'm looking at this again, and I'm wondering what's the use case that requires you to use both get_parameters and get_parameter with the same key. Can you expand a little on what are you trying to achieve? I need to understand the problem a little bit better in order to help the best way possible :)

@rubenfonseca I have a config class in my code that reads all my parameters from SSM on load and adds them as attributes of my config class. The code that loads the SSM parameters reads both individual parameters by name or multiple parameters by path. It does this by wrapping the get_parameter call in a try/except and then in the except block calling get_parameters.

For example, let's say I have an SSM path of /dev/auth and I have SSM parameters /dev/auth/client-id and /dev/auth/client-secret. The config class would look up all parameters under /dev/auth by first attempting to get_parameter("/dev/auth"). This would raise an exception and then the config class would call get_parameters("/dev/auth"). Once it receives the parameters it loops through them and adds them as attributes of the class so that I can call config.auth_client_id and config.auth_client_secret.

I ran into this issue because multiple modules will load the config class and get different values. So the first module to load the config class will go through the process above and get the correct parameter values to use locally. However, the second module to load the config class will call get_parameter("/dev/auth") and get the dictionary {"client-id": ..., "client-secret": ...} instead of raising an exception. Then the individual parameters under /dev/auth do not get added correctly as attributed to my config class in that second module.

@leandrodamascena
Copy link
Contributor

Hi @beck3905! Thanks for explaining in detail your use case and what we can to help you.

We agree that we should split caching between single fetch and multi fetch to avoid errors like this one. Do you have the bandwidth to send a PR fixing this? It would be awesome to have your code contribution to the Powertools project.

@leandrodamascena leandrodamascena added parameters Parameters utility and removed need-customer-feedback Requires more customers feedback before making or revisiting a decision labels Jun 20, 2023
@leandrodamascena leandrodamascena moved this from On hold to Pending customer in Powertools for AWS Lambda (Python) Jun 20, 2023
@heitorlessa
Copy link
Contributor

Checking in to confirm whether there's been any updates.

@heitorlessa heitorlessa moved this from Pending customer to On hold in Powertools for AWS Lambda (Python) Jul 10, 2023
@heitorlessa heitorlessa added enhancement and removed bug Something isn't working labels Jul 10, 2023
@heitorlessa
Copy link
Contributor

Confirmed with @leandrodamascena that we were waiting for another contributor who signaled wanted to pick this one up as a learning exercise.

It's a bug and we should fix it soon. If we don't hear from this contributor who wants to tackle it by EOD, I'll re-assign it and start working on this for the next release.

Apologies for the delay, we got our wires crossed when prioritizing it (bug not bug?)

@heitorlessa heitorlessa moved this from On hold to Working on it in Powertools for AWS Lambda (Python) Jul 10, 2023
@heitorlessa heitorlessa added bug Something isn't working and removed enhancement labels Jul 10, 2023
@leandrodamascena
Copy link
Contributor

Hello everyone! @paritosh16 will start working on this!

@heitorlessa
Copy link
Contributor

Maintainer took over and we're releasing this fix today. Apologies on the coordination issue we had; we normally fix a bug within the same day, this was an exception.

We've fixed our process issue to prevent bug fixes being dependent on non-maintainers.

Thank you for the patience.

@heitorlessa heitorlessa linked a pull request Jul 25, 2023 that will close this issue
13 tasks
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Jul 25, 2023
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY 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 tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jul 25, 2023
@github-actions
Copy link
Contributor

This is now released under 2.22.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jul 25, 2023
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parameters Parameters utility
Projects
Status: Shipped
5 participants