Fix #2275: Support YAML for complex CLI parameters #10051
+264
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description: Support YAML for complex CLI parameters (Fixes #2275)
Overview
This PR addresses a long-standing feature request (#2275) to support YAML files and strings for complex CLI parameters. Previously, parameters expecting structures, maps, or lists only supported JSON format when passed as strings or via
file://.Changes
awscli/argprocess.pyto attempt YAML parsing if the input is not clearly JSON (i.e., it doesn't start with{or[)._unpack_yaml_cli_arg) that usesyaml.SafeLoaderbut preserves key order usingOrderedDict. This ensures the behavior is consistent with the existing JSON parser and respects the order required by some AWS services.TestYAMLParamstotests/unit/test_argprocess.pycovering:Implementation Details
The core logic resides in
_unpack_complex_cli_arginawscli/argprocess.py. It now checks the first character of the input:{or[, it still uses the existing JSON unpacker._unpack_yaml_cli_argfunction.This approach maintains full backward compatibility for all existing JSON-based scripts while enabling YAML support.
Verification Results
test_argprocess.pyplus the 6 new YAML tests passed successfully.aws cloudformation create-stack --parameters file://params.yamlwith various YAML formats.aws cloudformation create-stack --parameters " - ParameterKey: K\n ParameterValue: V".Fixes
Fixes #2275