Skip to content

Add support for reading --cli-input-json and --cli-input-yaml from stdin#10272

Open
SebTardif wants to merge 1 commit intoaws:v2from
SebTardif:feat/cli-input-stdin
Open

Add support for reading --cli-input-json and --cli-input-yaml from stdin#10272
SebTardif wants to merge 1 commit intoaws:v2from
SebTardif:feat/cli-input-stdin

Conversation

@SebTardif
Copy link
Copy Markdown

Description

Add support for passing - as the value of --cli-input-json and --cli-input-yaml to read input from standard input. This enables clean pipeline usage:

cat params.json | aws s3api head-object --cli-input-json -
generate_yaml | aws s3api list-objects-v2 --cli-input-yaml -

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:

"I think it makes more sense to make a special case for --cli-input-json where it accepts - as a value that means read stdin. Much like aws s3 cp - s3://mybucket/stream.txt will copy stdin to a bucket."

The implementation adds a - check in CliInputArgument._get_arg_value() before the existing file:// resolution. This:

  • Follows the existing s3 cp - convention already established in the CLI
  • Is scoped to --cli-input-json / --cli-input-yaml only — avoids interactive mode conflicts raised in PR added support for using stdin and pipes #3209
  • Reads stdin exactly once — avoids the double-read problem that breaks file:///dev/stdin workarounds
  • Works cross-platform — no /dev/stdin dependency (works on Windows)
  • Does NOT add a generic pipe:// or stdin:// scheme — keeps the change minimal and focused

Testing

  • 4 new unit tests for JSON stdin: basic read, no-clobber, bad JSON, empty stdin
  • 1 new unit test for YAML stdin
  • 2 new functional tests for JSON stdin: basic read, CLI arg override
  • 1 new functional test for YAML stdin

All existing tests continue to pass. The inherited test structure ensures YAML tests also get the JSON stdin tests via class inheritance.

Changes

File Change
awscli/customizations/cliinput.py Add sys import; add - stdin check in _get_arg_value(); update help text for both JSON and YAML arguments
tests/unit/customizations/test_cliinput.py Add 5 stdin test methods
tests/functional/test_cliinput.py Add 3 stdin test methods
.changes/next-release/cli-input-stdin.json Changelog entry

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant