vgnshiyer
vgnshiyer

Reputation: 21

Can we launch a task in Fargate Launch type, if there is not enough memory in ECS instances?

We have an ECS cluster which currently has two instances.

There are few tasks which run on adhoc basis, triggered by the application itself. We are thinking of a scenario when there is not enough memory on the EC2 instances to accommodate the adhoc tasks. In that case can we run these tasks with launch type FARGATE, so that we don't need to provision a new EC2 unnecessarily.

Upvotes: 0

Views: 426

Answers (1)

Nick
Nick

Reputation: 199

I get the concern about the cost being the major factor behind the approach. If it's ad-hoc and won't be a frequent process, you can run it directly on fargate.

There are two major approaches you can explore:

  1. If you are running some script (Python, c#, node, go) and the process takes less than 15 mins, switch to AWS lambda. You'll be saving costs and it matches your use case.

  2. If your workload takes more than 15 mins. Use lambda to start the fargate service, by setting the desired count to 1 (or multiple, to match your use case) and call lambda from inside the container to turn off the service, by setting the count to 0 once the process is done.

We follow step 2 to save costs for our dev environments.

for point 2, a simple python script to toggle desired count property will do the trick.

AWS SDK for python(ECS): https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html

Both the steps will be efficient assuming you don't know the usage/trigger pattern.

I will highlight if your triggers are scheduled. you can use fargate with scheduled tasks.

Refer to AWS docs for above. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduling_tasks.html

Upvotes: 1

Related Questions