Containers-roadmap: [Fargate, ECS] [request]: Event Rule to set Desired Count to 0

Created on 21 Mar 2019  路  4Comments  路  Source: aws/containers-roadmap

Tell us about your request
Using ECS/Fargate as a backend, meaning once started my tasks are always up, until I explicitly request to stop the service.
Im trying to use AWS::Events::Rule with ecsParameters in Targets to schedule this shutdown of my service.

Which service(s) is this request for?
This could be Fargate, ECS

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?
CloudFormation is enforcing a taskCount > 1.

1 validation error detected: Value '0' at 'targets.1.member.ecsParameters.taskCount' failed to satisfy constraint: Member must have value greater than or equal to 1 (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException;

Type: 'AWS::Events::Rule'
Properties:
  Description: "app000 Stop Rule"
  Name: "app000-stop-000"
  ScheduleExpression: "cron(0 19 * * ? *)"
  State: DISABLED
  Targets:
   - Arn: !Ref "cluster"
     EcsParameters:
       **TaskCount: 0**
       TaskDefinitionArn: !Ref "app00TD"
     Id: "app00-target"

Are you currently working around this issue?
It's possible to schedule a Lambda that will set DesiredCount to 0, bypassing default integration between Events and ECS.

Proposed

Most helpful comment

Thanks @clareliguori, Application Autoscaling indeed supports scheduled actions and serves exactly my purpose.
As feature request, It would be great to update ECS doc to mention the availability of this feature (and enhance the GUI too :) )

Closing this ticket as original topic is addressed.

All 4 comments

If possible, I would like to have a similar one that manipulates the scalable parameters. I work with enterprise solution that is heavily used during business hours and we keep more than 1 container for high availability. Some services have a minimum of 4 containers. However, after business hours we could easily reduce to 2 and after 10 PM we could even reduce to 1 container and increase it back at 6 AM.
Weekends would be the same thing, running only 1 container per service. That could reduce the cost of ECS by 50% in our entire operation. We haven't reached out to doing this on a Lambda function yet because we're still in growth mode and deliverying more micro-services first. If AWS could provide this on CloudFormation, it would save the hustle of writing custom lambda function to control ECS scaling.

Note that you can set other values. 2 or 4 are valid for cloudformation, however 0 isn't.

The CloudWatch Events ECS target only triggers new non-service-based tasks, for example if you wanted to schedule a "cron job" that kicked off a new task every 12 hours. It is not intended to be used to scale services. This is why it prevents you from setting the value to 0. If you wanted to stop triggering new tasks, you would disable the rule.

@pha6d and @deleugpn have you looked at Application Autoscaling? It supports scheduled actions, so you can increase or decrease the DesiredCount of an ECS service on a schedule:
https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html

Thanks @clareliguori, Application Autoscaling indeed supports scheduled actions and serves exactly my purpose.
As feature request, It would be great to update ECS doc to mention the availability of this feature (and enhance the GUI too :) )

Closing this ticket as original topic is addressed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tabern picture tabern  路  3Comments

AndrewMcFarren picture AndrewMcFarren  路  3Comments

tabern picture tabern  路  3Comments

MartinDevillers picture MartinDevillers  路  3Comments

abby-fuller picture abby-fuller  路  3Comments