Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion for ECS Patterns: Time based service scaling construct #3638

Closed
nathanpeck opened this issue Aug 13, 2019 · 6 comments · Fixed by #5079
Closed

Feature suggestion for ECS Patterns: Time based service scaling construct #3638

nathanpeck opened this issue Aug 13, 2019 · 6 comments · Fixed by #5079
Assignees
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library feature-request A feature should be added or improved. in-progress This issue is being actively worked on.

Comments

@nathanpeck
Copy link
Member

The pattern for creating a service that scales according to a time schedule is quite complicated, requiring at least two CloudWatch Events and a Lambda function: https://aws.amazon.com/premiumsupport/knowledge-center/ecs-time-based-scaling/

This would make a nice pattern in ecs-patterns to more easily abstract the creation of a service that can scale down during the night but scale up during business hours

@nathanpeck nathanpeck added the needs-triage This issue or PR still needs to be triaged. label Aug 13, 2019
@NGL321 NGL321 assigned SoManyHs and piradeepk and unassigned rix0rrr Aug 13, 2019
@NGL321 NGL321 added feature-request A feature should be added or improved. @aws-cdk/aws-ecs Related to Amazon Elastic Container and removed needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2019
@jogold
Copy link
Contributor

jogold commented Aug 14, 2019

This could be partially addressed by first implementing an AwsLambda event target as suggested in #2538. I plan to work on this maybe next week.

@SoManyHs SoManyHs added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Aug 19, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 30, 2019

Why does the scheduled scaling that Application AutoScaling support not suffice?

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-applicationautoscaling.ScalableTarget.html#scale-wbr-on-wbr-scheduleid-action

@jogold
Copy link
Contributor

jogold commented Aug 31, 2019

I think that only target tracking and step scaling are supported via Application Auto Scaling for the moment: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html

@nathanpeck
Copy link
Member Author

Actually it looks from the AWS Auto Scaling docs like ECS services are also supported, so it should be possible with the default Application AutoScaling. There is an example in the official docs for the commandline:

aws application-autoscaling put-scheduled-action --service-namespace ecs \
  --scalable-dimension ecs:service:DesiredCount \
  --resource-id service/default/web-app \
  --scheduled-action-name my-one-time-action \
  --schedule "at(2019-01-31T17:00:00)" \
  --scalable-target-action MaxCapacity=10

@piradeepk piradeepk removed the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Oct 3, 2019
@piradeepk
Copy link
Contributor

piradeepk commented Nov 15, 2019

This is actually pretty easy to do with an extra couple lines. Not sure a new construct would be valuable here, an example in the examples repo as well as the README might be enough.

Something along the lines of:

readonly schedules: { [key: string]: ScalingSchedule };

const albFargateService = new ApplicationLoadBalancedFargateService(this, 'FargateService', props);

const scalableTarget = albFargateService.service.autoScaleTaskCount({
  minCapacity: props.minScalingCapacity !== undefined ? props.minScalingCapacity : this.desiredCount,
  maxCapacity: props.maxScalingCapacity !== undefined ? props.maxScalingCapacity : this.maxCapacity,
});

for (const [scheduleId, scheduleProps] of Object.entries(props.schedules)) {
  scalableTarget.scaleOnSchedule(scheduleId, scheduleProps);
}

Thoughts? @rix0rrr @nathanpeck

@piradeepk
Copy link
Contributor

Added to README: #5079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library feature-request A feature should be added or improved. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants