Skip to content

Bug: AppConfigProvider retrieves wrong value #2362

Closed
@scottgerring

Description

@scottgerring

Expected Behaviour

When I call parameters.get_parameter using the AppConfigProvider more than once with different parameter names, I expect to get the corresponding values for each configuration profiles in AppConfig.

The code in the _get method on AppConfigProvider stores the configuration session from the first time it is called and re-uses it. The problem is that the configuration session is associated with a single configuration profile, and you can see that the name parameter is ignored once a session is started. Here you can see the retrieval and storage of the token irrespective of the name of the field:

https://github.com/awslabs/aws-lambda-powertools-python/blob/5aece716496e1ce4220b2f2dcb399eceaefc976b/aws_lambda_powertools/utilities/parameters/appconfig.py#L100-L116

I've also noticed that DEFAULT_PROVIDERS holds a copy of an AppConfigProvider established using the application and environment from the first call, and re-uses it:

https://github.com/awslabs/aws-lambda-powertools-python/blob/5aece716496e1ce4220b2f2dcb399eceaefc976b/aws_lambda_powertools/utilities/parameters/appconfig.py#L198-L202

I think this means that we'll also not be able to provide a different application or environment for subsequent calls - in this case, I imagine it could be by design (a running application has a single identity and a single environment?)

Current Behavior

The first call works as expected, the second call returns the value from the configuration profile associated with the first call.

Code snippet

These will both end up with the value of param1:

        param_1 = parameters.get_app_config(name="param1", environment="dev", application="example")
        param_2 = parameters.get_app_config(name="param2", environment="dev", application="example")

Possible Solution

Powertools for typescript stores the session tokens keyed on the parameter / configuration profile name:

https://github.com/awslabs/aws-lambda-powertools-typescript/blob/0021536e35ba7046226155055f9ab6b5f988f71f/packages/parameters/src/appconfig/AppConfigProvider.ts#L264-L270

Steps to Reproduce

Fetch two different parameters within the same lambda execution

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.7

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Labels

bugSomething isn't workingparametersParameters utility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions