Search code examples
jsonamazon-web-servicesamazon-ecsamazon-vpcaws-fargate

Getting "cli-input-json' : invalid json received"


I am trying to run a service using Fargate launch type in AWS ECS. Following is my service-definition.json file.

{
  "serviceName": "MyService",
  "cluster": "arn of my cluster",
  "launchType": "FARGATE",
  "deploymentConfiguration": {
    "maximumPercent": 200,
    "minimumHealthyPercent": 0
  },
  "desiredCount": 1,
  "networkConfiguration": {
    "awsvpcConfiguration": {
      "assignPublicIp": "DISABLED",
      "securityGroups": [
        "sec-group-id"
      ],
      "subnets": [
        "subnet-1",
        "subnet-2"
      ]
    }
  },
  "taskDefinition": "mytask",
  "loadBalancers": [
    {
      "containerName": "mytask-container",
      "containerPort": 8080,
      "targetGroupArn": "arn to my target group"
    }
  ]
}

On running this command : aws ecs create-service --cli-input-json service-definition.json. I get invalid json error.

I have validated my json for syntax. I just want to confirm whether this definition is logically 'ok' to work ? If not, corrections are welcome.


Solution

  • When you want to use a file, you have to use the following format (file://) for cli-input-json:

    aws ecs create-service --cli-input-json file://service-definition.json
    

    Example is in the create-service docs.