3
votes

I have a Fargate app running in AWS ECS, which I'm trying to update by the AWS CLI (aws-cli/1.16.96 Python/2.7.15 Darwin/18.0.0 botocore/1.12.86 ).

I've built and pushed the image successfully, and created a new task definition version.

When I'm trying to update the service with the following commands :

aws ecs update-service 
    --cluster cluster-winquest-qa 
    --service container-qa-ge-service 
    --desired-count 0
aws ecs update-service 
    --cluster cluster-qa 
    --service container-service 
    --task-definition first-run-task-definition:5 
    --platform-version "LATEST"  
    --desired-count 1

Throws the following error message :

An error occurred (InvalidParameterException) when calling the UpdateService operation: Task definition does not support launch_type FARGATE

Then I tried to add --launch-type "FARGATE" to the command above mentioned, building the following command :

aws ecs update-service 
    --cluster cluster-qa 
    --service container-service 
    --task-definition first-run-task-definition:5 
    --platform-version "LATEST" 
    --launch-type "FARGATE"  
    --desired-count 1

It throws : Unknown options: --launch-type, FARGATE

I know that the error mesage said that the task definition is not supported for Fargate apps, but I want to know how can I update the service to the lastest task definition version using AWS CLI. I would appreciate any help. Thanks.

3

3 Answers

1
votes

I solved it. The problem was how I was creating the new version of the task definition, there I had to configure requiresCompatibilities param to specify it.

I used this doc: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_Fargate.html

0
votes

If you look at ecs command line reference here update-service does not support --launch-type flag. The reason it does not support this flag is because you are trying to update a service which is already created. You can only specify launch type when you are running create-service (here).

The reason you might be getting the first error is because you did not create the cluster using Powered by AWS Fargate cluster type. You are using --platform-version flag which is only used for Fargate type of clusters (mentioned in AWS documentation).

Also, to let your service use the latest task definition you can simply not use the --task-definition flag because by default if a revision is not specified it uses the latest ACTIVE revision.

0
votes

Had this same issue while setting up an Amazon ECS cluster using Terraform.

All you need to do is to add this attribute below to your aws_ecs_task_definition block:

requires_compatibilities = ["FARGATE"]

So your task definition file will look somehow like this:

resource "aws_ecs_task_definition" "aetd" {
  family                   = var.family
  network_mode             = var.network_mode
  requires_compatibilities = ["FARGATE"]
  cpu                      = var.cpu
  memory                   = var.memory
  execution_role_arn       = var.execution_role_arn
  task_role_arn            = var.task_role_arn
  container_definitions = jsonencode([
...
...
}

That's all.