2

I have a service which runs 1 task. The task takes 2 hours to run and runs daily. My ideal scenario would be this:

  1. I update my service to from 0 desired tasks to 1 desired task
  2. ECS sees that in order to run the service I need an EC2 Instance. It therefore spins up an instance to run the task.
  3. When the task finishes it updates the service to 0 desired tasks.
  4. ECS sees that I don't need the instance to run 0 tasks and turns it off

Using the ECS admin it looks like this is possible but in reality, when I scale up my service from 0->1 task, it just complains there is no instances to run the task, rather than autoscaling an instance. I set the auto scale policies of the cluster to min=0, desired=1, max=1 however it makes no difference.

I'd like to know if my ideal scenario is indeed possible, or if there is a better way to achieve this goal.

Thanks in advance,

MrDuk
  • 16,578
  • 18
  • 74
  • 133
rix
  • 10,104
  • 14
  • 65
  • 92
  • You're use of _container_ is incorrect. An instance is not a container, assuming you're referring to _EC2 Instances_, and not _an instance of your container_. Either way, please edit your question with clarification. – MrDuk Feb 21 '18 at 19:01
  • I'm referring to what ECS terms a 'Container instances' which correlates to the underlying EC2 instance (as far as i can see). – rix Feb 21 '18 at 21:29
  • This is not possible. To run a task, precondition is an active container. I think AWS Lambda fits your use case. – S.K. Feb 23 '18 at 06:54
  • @S.K. that's not at all true - ECS will create a new container based on your task definition; it doesn't update existing containers with your task definition (keeping in mind that _container_ shouldn't be confused with _ec2 instance_) – MrDuk Feb 23 '18 at 20:19
  • @rix are you in a region that supports [Fargate](https://aws.amazon.com/fargate/)? – MrDuk Feb 23 '18 at 20:25
  • I am in a region that supports Fargate but I'm not interested in paying more for a use case that should be supported by ECS. Also lambda wouldn't fit my use case. – rix Feb 24 '18 at 09:05

1 Answers1

2

Unfortunately point 2 and 4 is not true for ECS (EC2 launch type). By default it will neither launch the EC2 instance nor terminate the instance.

Actually FARGATE is more costlier than ECS(EC2 lauch type). But for your use case FARGATE will be much more cheaper [1] compare to ECS(EC2 lauch type).

But again FARGATE would not be the best option. According to your use case best option would be AWS Batch [2]. Batch uses the ECS as a back end and main advantage using batch is it will also perform the step 2 and step 4 mentioned in your use case.

[1] https://aws.amazon.com/fargate/pricing/

[2] https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html

Mech
  • 1,326
  • 11
  • 14