Fix #2275: Support YAML for complex CLI parameters#10051
Open
Ashutosh0x wants to merge 2 commits intoaws:developfrom
Open
Fix #2275: Support YAML for complex CLI parameters#10051Ashutosh0x wants to merge 2 commits intoaws:developfrom
Ashutosh0x wants to merge 2 commits intoaws:developfrom
Conversation
This fixes a long-standing issue where strings like '1e10' or '0755' were being output without quotes by 'aws cloudformation package', causing them to be misinterpreted as numbers when re-parsed. Added a custom string representer to yaml_dump that identifies and quotes ambiguous strings (scientific notation, octal, hex, binary, and sexagesimal formats).
This change enables YAML support for all complex CLI parameters (structures, maps, and lists) by updating the argument unpacking logic in argprocess.py.
Previously, complex parameters only supported JSON for file or string inputs. Now, if the input is not clearly JSON (doesn't start with '{' or '['), the CLI will attempt to parse it as YAML.
This allows using YAML files for CloudFormation parameters and other nested CLI inputs:
- aws cloudformation create-stack --parameters file://params.yaml
Included unit tests in tests/unit/test_argprocess.py covering various YAML input scenarios.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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