amazon-ecs-cli icon indicating copy to clipboard operation
amazon-ecs-cli copied to clipboard

Create or update service without starting it is currently not possible

Open artur-jablonski opened this issue 7 years ago • 11 comments
trafficstars

I can use ecs-cli compose --file docker-compose.yml service up To create a service if it doesn't exist, update if it does and then start it, but there seem not to be a way of doing a similar thing but WITHOUT starting the service.

The ecs-cli compose --file docker-compose.yml create will work if the service doesn't exist, but it will fail if it does.

artur-jablonski avatar Jul 11 '18 15:07 artur-jablonski

@artur-jablonski can you elaborate further on this feature request? It would help if I could understand your use case better. In ECS, there are 4 actions in ECS related to managing a service:

  1. Creating the Service
  2. Creating a Task Definition
  3. Updating the service desired count of tasks (when the ECS CLI starts a service, it just increments this count from 0 to 1)
  4. Updating the Task Definition that the Service uses

It sounds like you want to update the task definition on a service which has a desired count of 0? Is that really what you need or do you just want to register a new version of a task definition?

PettitWesley avatar Jul 17 '18 18:07 PettitWesley

Hello,

That is correct: I want to create a service if it doesn't exist or update a task of a service with desired count of 0 if it does. I want to do it via docker-compose files. So pretty much what ecs-cli service up is doing but without changing the desired count.

The use case is that we have some containers that are started on demand by AWS lambdas, so we don't want to start them when creating/updating the service

artur-jablonski avatar Jul 18 '18 14:07 artur-jablonski

@artur-jablonski, thanks for your feedback, I've marked this as a feature request. I think ideally for your use case ecs-cli compose service create would call update service if the service already existed.

In the mean time, I would suggest using ecs-cli compose create to create your task definition and then use the AWS CLI to update the ECS Service to use that new task definition.

PettitWesley avatar Jul 18 '18 22:07 PettitWesley

Hello @PettitWesley , yes, if service create was doing that, it would make me happy.

As for your suggestion about using AWS CLI to update task, it's, as far as I understand a bit involved as we would need to create the task definition document somehow (probably based on our docker-compose), so for now what we do we use ecs-cli service delete and then ecs-cli service create. It's ugly, but it works. Kindo of, one problem is that when ecs-cli service delete returns, the ECS (or whatever) has not yet fully cleaned up stuff so if we issue ecs-cli service create immediately after, it fails. I am not sure, but perhaps it deserves a separate ticket.

artur-jablonski avatar Jul 19 '18 08:07 artur-jablonski

[Edited] @artur-jablonski, the ecs-cli can create the task definition for you- ecs-cli compose create creates a task definition from your docker compose file, that's all. The output of the command will give you the name of the new task definition, then you update your service to use that task definition like this: aws ecs update-service --service <val> --task-definition <name>

PettitWesley avatar Jul 19 '18 17:07 PettitWesley

@PettitWesley . That is not what I observe. ecs-cli compose service create will fail if the service with given name already exists, so I cannot use it to update a task definition like you're describing.

artur-jablonski avatar Jul 23 '18 08:07 artur-jablonski

this is the error message if you try to do service create on service that alredy exists

time="2018-07-23T08:41:33Z" level=fatal msg="InvalidParameterException: Creation of service was not idempotent.\n\tstatus code: 400, request id: 3410237a-8e54-11e8-a974-1fd3e6c4ce19"

artur-jablonski avatar Jul 23 '18 08:07 artur-jablonski

@artur-jablonski Sorry, I meant ecs-cli compose create, which doesn't involve services and just creates a task definition. I've edited my comment.

$ ecs-cli compose create --help
NAME:
   ecs-cli compose create - Creates an ECS task definition from your compose file. Note that we do not recommend using plain text environment variables for sensitive information, such as credential data.

USAGE:
   ecs-cli compose create [command options] [arguments...]

PettitWesley avatar Jul 23 '18 17:07 PettitWesley

@PettitWesley . Right, I see. This can work, though I guess aws ecs update-service requires the service to be present already.

I will give it a try and see. Thanks for the suggestion

artur-jablonski avatar Jul 25 '18 09:07 artur-jablonski

@artur-jablonski I'd like to get your opinion on one idea. For ecs-cli up we have a --force flag that forces deletion and then re-creation of all resources. What would you think about adding a --force option to ecs-cli compose service create?

PettitWesley avatar Jul 25 '18 23:07 PettitWesley

What's the ultimate fate of this?

rulatir avatar Nov 15 '21 10:11 rulatir