- Newest
- Most votes
- Most comments
Is this something you want to recur on a schedule, or have some other business logic to know when they should happen? You can create a Scheduled Action either for a 1 time action, or recurring on a cron
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.ScheduledAction.html
Yes, it's possible to dynamically change the auto scaling min and max limits for an ECS Fargate service after deployment. You can do this by accessing the scalable target that was created for your service.
In TypeScript, you can modify the auto scaling configuration of an existing ECS Fargate service like this:
// Assuming you have a reference to your existing service const loadBalancedFargateService = /* your existing service reference */; // Get or create the scalable target const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({ minCapacity: 5, // New minimum capacity maxCapacity: 30, // New maximum capacity }); // You can also update or add scaling policies scalableTarget.scaleOnCpuUtilization('CpuScaling', { targetUtilizationPercent: 60, // Adjust target utilization as needed }); scalableTarget.scaleOnMemoryUtilization('MemoryScaling', { targetUtilizationPercent: 60, // Adjust target utilization as needed });
When you call autoScaleTaskCount() on an existing service, it will either create a new scalable target if one doesn't exist, or update the existing one with the new capacity values.
If you need to update the scaling configuration outside of a CDK deployment (e.g., in response to an event or on a schedule), you would need to use the AWS SDK for TypeScript (AWS SDK for JavaScript v3) to call the Application Auto Scaling API directly. This would involve using the RegisterScalableTarget API to update the min and max capacity values for your ECS service.
Sources
interface EnableScalingProps · AWS CDK
aws-cdk-lib.aws_ecs_patterns module · AWS CDK
answered a year ago
Relevant content
asked 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago

This is something I want to be able to do programatically based on some events.
If you add an AutoScalingScheduledAction policy, then you should be able to make Scheduled Actions out of band (directly through the SDK, not in the CDK), and CloudFormation will ignore the changes made to min/max/desired during stack updates; unless you explicitly change a value in the ASG resource of the template.
https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-scheduledactions