2

I want to know if it is possible in any way to update this field "Minimum Number of Tasks" (no matter the language, if is available in lambda)

Why ? Because I have problems with the balancer that I have linked to the service.

From the NodeJS SDK, I can change the desired tasks field which is fine, but the tasks created are stopped by the alarms that I have in Cloudwatch.

What I see is that I have to update the two so that they do not stop.

How can edit this field in my service of my cluster on ecs?

CrlsPerez
  • 117
  • 1
  • 10

3 Answers3

2

Check the ApplicationAutoScaling class. I'm not familiar with this particular SDK, but application autoscaling is where min and max tasks are defined in boto3 and in the awscli.

bluescores
  • 4,437
  • 1
  • 20
  • 34
  • Tx your answer help me to modify my application, but my application is not "normal", at the end I create two lambdas one disable the alarm of autoscaling when the event is called by the api, the second with one cron enable the alarm if match with something of data. – CrlsPerez Nov 08 '18 at 17:07
1

Taking the reference from this link, you'll have to do it in 2 steps, using application auto-scaling boto3 client:

  1. Create your ECS service as Application auto-scaling target with register_scalable_target() with for example MinCapacity=3 and MaxCapacity=100. This call will return the scalable target ARN.
  2. Every evening call register_scalable_target() again with MinCapacity=0 and every business day morning again with MinCapacity=3.

See the register_scalable_target() documentation where it explicitly says:

After you have registered a scalable target, you can use this operation to update the minimum and maximum values for its scalable dimension.

Your auto-scaling policy will then set DesiredCapacity within the Min/MaxCapacity boundaries where the MinCapacity will change from 0 to 3 during business hours and back to 0 after hours.

  • that's the desired count, not minimum number of tasks – Stéphane Bruckert Nov 11 '20 at 10:20
  • Hey Stéphane, thanks for the comment and downvote, I probably was daydreaming when I read the question for the first time. Anyways, I have edited the answer to the best of my knowledge and what I found from googling – Sajjan Mishra Nov 12 '20 at 01:02
0

To update a scalable target, specify the parameters that you want to change. Include the parameters that identify the scalable target: resource ID, scalable dimension, and namespace. Any parameters that you don't specify are not changed by this update request.

https://docs.aws.amazon.com/sdk-for-go/api/service/applicationautoscaling/#ApplicationAutoScaling.RegisterScalableTarget

This golang example shows how to update the minimum number of tasks (minimum capacity) of an ECS service:

import (
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/applicationautoscaling"
)

sess, _ := session.NewSession()
aas := applicationautoscaling.New(sess)

res, err := aas.RegisterScalableTarget(
    &applicationautoscaling.RegisterScalableTargetInput{
        MinCapacity: aws.Int64(int64(5)),
        ServiceNamespace: aws.String("ecs"),
        ResourceId: aws.String("service/cluster_name/service_name"),
        ScalableDimension: aws.String("ecs:service:DesiredCount"),
    },
)
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130