AWS CLI,在管道中使用 `--cli-input-json`

Att*_*tie 5 command-line amazon-web-services

我想aws在管道中使用命令行应用程序,但似乎不可能。

一个工作示例是:

$ aws ecs register-task-definition --cli-input-json file://./mytask.json
Run Code Online (Sandbox Code Playgroud)

但是,以下不起作用:

$ cat ./mytask.json \
    | aws ecs register-task-definition --cli-input-json file:///dev/stdin

Error parsing parameter 'cli-input-json': Invalid JSON: Expecting value: line 1 column 1 (char 0)
JSON received:
Run Code Online (Sandbox Code Playgroud)
$ aws ecs register-task-definition --cli-input-json file://<(cat ./mytask.json)

Error parsing parameter 'cli-input-json': Invalid JSON: Expecting value: line 1 column 1 (char 0)
JSON received:
Run Code Online (Sandbox Code Playgroud)

166*_*MMX 6

暂时找到了一个非常干净的 xargs 解决方法:

cat ./mytask.json \
    | xargs -0 aws ecs register-task-definition --cli-input-json
Run Code Online (Sandbox Code Playgroud)

它只添加xargs -0要求 --cli-input-json是最后一个参数

  • 这将一直有效,直到 JSON 变得太大(诚然,在我的系统上约为 2MiB)。 (3认同)

Att*_*tie 5

我去挖掘......看起来aws会读取指定的文件两次,使用第二个数据集进行操作。当然,在管道中,第二个read()将一无所获。

我已经添加了一个pipe://前缀/模式(commit),用于在这种情况下缓存值......我还提出了一个拉取请求