We have changed from using ECS clusters running EC2 services and tasks to using ECS clusters running services with Fargate tasks. Each of these ECS clusters represents a group of tasks making up an instance of an application.
We need to find a way to easily schedule the scaling of the tasks within a service based on time, e.g. to shut down and restart our test and QA environments overnight and at weekends.
We did consider Kubernetes (EKS) but decided to go the ECS route due to pricing and deployment effort considerations. I’m sure that some other smaller companies may come to the same conclusion.
We raised a ticket with AWS and received the following response -
I understand that you would like to know how to schedule fargate tasks to run on scheduled time of the day and stop at the end of the day as a cost optimization initiative for your development and test environments.
Currently, ECS supports only scheduling starting of tasks using cron like expressions or cloudwatch events for the fargate launch type as here . However natively this primarily is meant for short running tasks and does not have a native option to stop tasks on a schedule. In other words, this is for tasks that are only meant to perform a specific action and then stop, and one would consider having your containers simply exit once the operation completes. This way you would not need to manually stop the tasks.
Therefore for your use case you would use the ECS schedule tasks cron to start your task in the morning, however, to stop the task the work around, would be to consider use of a lambda function that would get triggered by a CloudWatch event to update the desired count of tasks in your service to 0 at night. Here are documentation that would help guide you in this case , please test adjusting the code to stop task.
I would also like to mention that there is an ongoing feature request with our service team however we currently do not have an ETA on when this will be released and I have added this case as part of our customer requirements.
I trust this correspondence proves useful. However Should you have any further issues or need additional clarification, please feel free to get back to us and we will be happy to assist you.
 Scheduled tasks
 Tutorial: Listening for Amazon ECS CloudWatch Events - https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs_cwet.html
 https://github.com/s7anley/aws-ecs-service-stop-lambdaemphasized text**
Any help anyone could provide would be greatly appreciated.