Skip to content

fix(parameters): ignore malformed POWERTOOLS_PARAMETERS_SSM_DECRYPT instead of crashing - #8839

Open
saquibjawedbit wants to merge 1 commit into
aws-powertools:developfrom
saquibjawedbit:fix/parameters-ssm-decrypt-env-var
Open

saquibjawedbit wants to merge 1 commit into
aws-powertools:developfrom
saquibjawedbit:fix/parameters-ssm-decrypt-env-var

Conversation

@saquibjawedbit

Copy link
Copy Markdown

Issue number:
closes #8798

Summary

Changes

The six SSM entry points now read POWERTOOLS_PARAMETERS_SSM_DECRYPT through the shared resolve_bool_env_var from #8783, as suggested in the issue. Same shape as #8734 did for idempotency.

  • aws_lambda_powertools/utilities/parameters/ssm.py: in SSMProvider.get, SSMProvider.get_multiple, SSMProvider.get_parameters_by_name, get_parameter, get_parameters and get_parameters_by_name, replace resolve_truthy_env_var_choice(env=os.getenv(..., "false"), choice=decrypt) with if decrypt is None: decrypt = resolve_bool_env_var(constants.PARAMETERS_SSM_DECRYPT_ENV). The env var is only read when no decrypt argument is passed. The now-unused os and resolve_truthy_env_var_choice imports are removed.
  • tests/functional/parameters/_boto3/test_utilities_parameters.py: functional tests across all six public entry points, using botocore.stub.Stubber to assert the WithDecryption value sent to SSM:
    • "" and "maybe": the lookup succeeds without decryption and emits a PowertoolsUserWarning naming the variable (12 cases).
    • "true", "1", "false", "0": decryption follows the variable and no warning is emitted (24 cases).
    • explicit decrypt=True / decrypt=False with 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 the decrypt argument are unchanged.

User experience

Before: with POWERTOOLS_PARAMETERS_SSM_DECRYPT="" (or any value that is not a recognised boolean) and no decrypt argument, every SSM lookup raised ValueError: invalid truth value '' before calling SSM.

After: the lookup goes ahead without decryption (the documented default) and a PowertoolsUserWarning is emitted:

POWERTOOLS_PARAMETERS_SSM_DECRYPT has an unrecognised value ''. Falling back to False.

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 (the make dev deps). SSM calls are stubbed with botocore.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 for decrypt=False.

Fails before the fix (new tests, ssm.py from origin/develop):

$ uv run --locked pytest tests/functional/parameters/_boto3/test_utilities_parameters.py -k "decrypt_env_var" -q
aws_lambda_powertools/utilities/parameters/ssm.py:240: in get
    decrypt = resolve_truthy_env_var_choice(
aws_lambda_powertools/shared/functions.py:58: in resolve_truthy_env_var_choice
    return choice if choice is not None else strtobool(env)
...
E       ValueError: invalid truth value ''
...
E           Failed: DID NOT WARN. No warnings of type (<class 'aws_lambda_powertools.warnings.PowertoolsUserWarning'>,) were emitted.
...
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-SSMProvider.get]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-SSMProvider.get_multiple]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-SSMProvider.get_parameters_by_name]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-get_parameter]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-get_parameters]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-get_parameters_by_name]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-SSMProvider.get]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-SSMProvider.get_multiple]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-SSMProvider.get_parameters_by_name]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-get_parameter]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-get_parameters]
FAILED tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-get_parameters_by_name]
=========== 12 failed, 36 passed, 183 deselected, 1 warning in 7.88s ===========

(The 36 passing cases are the valid-value and explicit-argument tests, which guard existing behaviour and pass on both.)

Passes after the fix:

$ uv run --locked pytest tests/functional/parameters/_boto3/test_utilities_parameters.py -k "decrypt_env_var" -v
...
tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[-SSMProvider.get] PASSED [  2%]
tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_invalid_decrypt_env_var_warns_and_does_not_decrypt[maybe-get_parameters_by_name] PASSED [ 25%]
tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_with_valid_decrypt_env_var[true-True-SSMProvider.get] PASSED [ 27%]
tests/functional/parameters/_boto3/test_utilities_parameters.py::test_ssm_lookup_explicit_decrypt_wins_over_invalid_decrypt_env_var[False-get_parameters_by_name] PASSED [100%]
================ 48 passed, 183 deselected, 1 warning in 4.46s =================

Parameters and shared-function suites:

$ uv run --locked pytest tests/functional/parameters tests/unit/test_shared_functions.py tests/unit/shared -q
======================= 355 passed, 1 warning in 20.10s ========================

Lint and types:

$ make format-check lint-check
1417 files already formatted
All checks passed!

$ make mypy
Success: no issues found in 963 source files

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.

…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.
@saquibjawedbit
saquibjawedbit requested a review from a team as a code owner November 15, 2026 17:38
@boring-cyborg boring-cyborg Bot added the tests label Nov 15, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: invalid POWERTOOLS_PARAMETERS_SSM_DECRYPT values crash SSM lookups

1 participant