Repository navigation
fix(parameters): ignore malformed POWERTOOLS_PARAMETERS_SSM_DECRYPT instead of crashing - #8839
Conversation
…nstead of crashing An empty or unparsable value made every SSM lookup raise ValueError before any API call. The six SSM entry points now read the variable through the shared resolve_bool_env_var, which warns with PowertoolsUserWarning and falls back to False. An explicit decrypt argument still takes precedence and the variable is not read.
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @saquibjawedbit! Reading the variable only when decrypt is not passed keeps the precedence exactly as it was, and the Stubber tests asserting WithDecryption on all six entry points are the right level to test this. I ran it against a real SecureString parameter with "", "maybe", "true" and "false", and it behaves as described. Goes out in 3.42.0, no need to rebase, you'll be in the release notes.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8839 +/- ##
========================================
Coverage 97.14% 97.14%
========================================
Files 327 327
Lines 16785 16790 +5
Branches 1532 1538 +6
========================================
+ Hits 16306 16311 +5
Misses 336 336
Partials 143 143 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
a4eb1ff
into
aws-powertools:develop



Issue number:
closes #8798
Summary
Changes
The six SSM entry points now read
POWERTOOLS_PARAMETERS_SSM_DECRYPTthrough the sharedresolve_bool_env_varfrom #8783, as suggested in the issue. Same shape as #8734 did for idempotency.aws_lambda_powertools/utilities/parameters/ssm.py: inSSMProvider.get,SSMProvider.get_multiple,SSMProvider.get_parameters_by_name,get_parameter,get_parametersandget_parameters_by_name, replaceresolve_truthy_env_var_choice(env=os.getenv(..., "false"), choice=decrypt)withif decrypt is None: decrypt = resolve_bool_env_var(constants.PARAMETERS_SSM_DECRYPT_ENV). The env var is only read when nodecryptargument is passed. The now-unusedosandresolve_truthy_env_var_choiceimports are removed.tests/functional/parameters/_boto3/test_utilities_parameters.py: functional tests across all six public entry points, usingbotocore.stub.Stubberto assert theWithDecryptionvalue sent to SSM:""and"maybe": the lookup succeeds without decryption and emits aPowertoolsUserWarningnaming the variable (12 cases)."true","1","false","0": decryption follows the variable and no warning is emitted (24 cases).decrypt=True/decrypt=Falsewith the variable set to"maybe": the argument wins and no warning is emitted (12 cases).No existing tests were changed. No docs change: the documented default (
false) and the precedence of thedecryptargument are unchanged.User experience
Before: with
POWERTOOLS_PARAMETERS_SSM_DECRYPT=""(or any value that is not a recognised boolean) and nodecryptargument, every SSM lookup raisedValueError: invalid truth value ''before calling SSM.After: the lookup goes ahead without decryption (the documented default) and a
PowertoolsUserWarningis emitted:Valid values behave as before. An explicit
decrypt=argument still takes precedence, and the variable is not read at all in that case.Verification
AI-assisted; I ran the tests below myself and pasted the output.
Local run on macOS, Python 3.13.15, env synced with
uv sync --locked --extra all --extra redis --extra datamasking --extra valkey --extra auth-sigv4a(themake devdeps). SSM calls are stubbed withbotocore.stub.Stubber, which validates request parameters against the SSM service model; I did not run this against a real SSM endpoint. The fix happens before any SDK call, and the requests sent are the same ones the existing code already sends fordecrypt=False.Fails before the fix (new tests,
ssm.pyfromorigin/develop):(The 36 passing cases are the valid-value and explicit-argument tests, which guard existing behaviour and pass on both.)
Passes after the fix:
Parameters and shared-function suites:
Lint and types:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.