DataGuy
DataGuy

Reputation: 1725

AWS CLI - No JSON object could be decoded

Im using the CLI for AWS to create a cluster and use the parameters from a json file. Here is the CLI command string Im using:

aws emr create-cluster --name "Big Matrix Re Run 1" --ami-version 3.1.0 --steps file://Segmentgroup1.json --release-label --instance-groups InstanceGroupType=MASTER,InstanceCount=1,InstanceType=m3.xlarge InstanceGroupType=CORE,InstanceCount=2,InstanceType=m3.xlarge --auto-terminate

My json file (Segmentgroup1.json) is in the same folder in which Im running the AWS command string from, but I keep getting the following error:

No JSON object could be decoded

Based on what Ive found its not finding the json file. Any ideas?

Upvotes: 12

Views: 15713

Answers (3)

Maverick
Maverick

Reputation: 156

The problem that you are facing here is because of the way AWS CLI commands are exposed. They can either take JSON (as a string) directly from the command line or as a JSON file.

If you don't explicitly specify your intention by providing the file path in the URI format (prefixed with file://), the command treats the file path itself as a JSON string and gives you this error.

Upvotes: -1

Franke
Franke

Reputation: 1282

Here is an example command that works on Windows, where the file path syntax is a little different:

aws cloudwatch put-metric-data --namespace "EC2 Memory Usage" --metric-data file://C:\Users\Joe\mycode\metric.json

Upvotes: 1

nybon
nybon

Reputation: 9631

I ran into the same problem under my Mac, and I found the cause is the path for the json file instead of the content of the json file. To make it right:

  • You need to append file:// protocol as the prefix for your path
  • and use absolute path to your JSON file as parameter

Try something like this:

aws ecs register-task-definition --cli-input-json file://<absolute_path_to_json>/your_json.json

If you don't want to hard code the file path, you may use command like pwd to do this:

aws ecs register-task-definition --cli-input-json file://`pwd`/your_json.json

Upvotes: 33

Related Questions