I have various Fargate tasks. They work fine. I then have a few additional tasks that require more disc space than silly old Fargate will allow. These have to run on EC2 instances that I have assigned to their respective cluster.
I trigger these tasks using cloudwatch events.
Because I have so few of these EC2 powered tasks, it seems silly having these EC2 instances sitting around.
My thought was to create / destroy the EC2 instances on demand, probably by using Lambda.
My proposed sequence:
- Cloudwatch Start event
- Lambda auto scales the EC2 instances for the ECS cluster to 1
- EC2 Cloudwatch ready event
- ECS task is started
- ECS task finishes and triggers a Cloudwatch event
- Lambda down scales the cluster
Is this feasible? Is there a pattern or better way to do this? Perhaps the Lambda function is unnecessary if there's a way to trigger the autoscale straight from the cloudwatch event?
Please note that these tasks are not scheduled, so it's not a matter of scheduling the autoscaling