I'd like to use the aws command line application in a pipeline, but it doesn't appear to be possible.
A working example is:
$ aws ecs register-task-definition --cli-input-json file://./mytask.jsonHowever the following do not work:
$ 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:$ 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: 3 Answers
Found a workaround for the time being with xargs that is quite clean:
cat ./mytask.json \ | xargs -0 aws ecs register-task-definition --cli-input-jsonIt only adds xargs -0 and requires --cli-input-json to be the last argument
I went digging... It looks like aws will read the indicated file twice, using the second dataset for it's operation. Of course, in a pipeline, the second read() will get nothing.
I've added a pipe:// prefix/schema (commit) for use in this situation which will cache the value... I've also made a pull request.
I was able to pass the JSON as a variable on --cli-input-json and inject bash variables too.
So your example should be:
aws ecs register-task-definition --cli-input-json "$(cat < ./mytask.json)"In my scenario at hand I have:
Either pass a JSON as you would like
aws autoscaling start-instance-refresh --cli-input-json "$(cat < ./options.json )"Or as HEREDOC in order to pass other variables too. (Not requested but may be useful)
asg_nominal_name=AutoScalingGroupName
aws autoscaling start-instance-refresh --cli-input-json "$(cat <<JSON
{ "AutoScalingGroupName": "${asg_nominal_name}", "Preferences": { "InstanceWarmup": 300, "MinHealthyPercentage": 100 }
}
JSON
)"I am not so familiar to explain the why in bash terms. Feel free.
0