Add support for reading --cli-input-json and --cli-input-yaml from stdin#10272
Open
Add support for reading --cli-input-json and --cli-input-yaml from stdin#10272
Conversation
Add support for passing '-' as the value of --cli-input-json and --cli-input-yaml to read the input from standard input. This is consistent with the existing 'aws s3 cp -' convention and enables clean pipeline usage such as: cat params.json | aws s3api head-object --cli-input-json - The change is scoped to CliInputArgument._get_arg_value() to avoid conflicts with interactive mode in other parameters. Stdin is read exactly once, avoiding the double-read problem that affects file:///dev/stdin workarounds. Fixes aws#5982 Fixes aws#7850
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.
Description
Add support for passing
-as the value of--cli-input-jsonand--cli-input-yamlto read input from standard input. This enables clean pipeline usage:Fixes #5982
Fixes #7850
Motivation and Context
This has been requested since 2018 (PR #3209, issue #3700, issue #5982, issue #7850). Users need stdin support for:
Approach
Following the direction suggested by @stealthycoin in PR #3209:
The implementation adds a
-check inCliInputArgument._get_arg_value()before the existingfile://resolution. This:s3 cp -convention already established in the CLI--cli-input-json/--cli-input-yamlonly — avoids interactive mode conflicts raised in PR added support for using stdin and pipes #3209file:///dev/stdinworkarounds/dev/stdindependency (works on Windows)pipe://orstdin://scheme — keeps the change minimal and focusedTesting
All existing tests continue to pass. The inherited test structure ensures YAML tests also get the JSON stdin tests via class inheritance.
Changes
awscli/customizations/cliinput.pysysimport; add-stdin check in_get_arg_value(); update help text for both JSON and YAML argumentstests/unit/customizations/test_cliinput.pytests/functional/test_cliinput.py.changes/next-release/cli-input-stdin.json