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.json

However 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:

4 Answers 4


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-json

It only adds xargs -0 and requires --cli-input-json to be the last argument

  • 3
    This will work until the JSON becomes too large (admittedly ~2MiB on my system).
    – Attie
    Commented May 8, 2019 at 15:45
  • Same experience @Attie. Eventually on Linux systems you get an E2BIG error because the size of the command line arguments exceed ARG_MAX. Commented Jul 14, 2023 at 0:13

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:

  1. Either pass a JSON as you would like

    aws autoscaling start-instance-refresh --cli-input-json "$(cat < ./options.json )"

  2. Or as HEREDOC in order to pass other variables too. (Not requested but may be useful)


aws autoscaling start-instance-refresh --cli-input-json "$(cat <<JSON
    "AutoScalingGroupName": "${asg_nominal_name}",
    "Preferences": {
        "InstanceWarmup": 300,
        "MinHealthyPercentage": 100

I am not so familiar to explain the why in bash terms. Feel free.


In my case, it is the file encoding problem. Save your file in UTF-8 without BOM, then it will work.

If you use Sublime Text, then go to File -> Save with Encoding -> UTF-8.

In VS Code, at the bottom bar of VS Code, you'll see the label "UTF-8 with BOM". Click it to open the action bar and select "Save with encoding". Choose UTF-8 and save the file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .