SAndriy
SAndriy

Reputation: 808

How to set up Fargate Service Auto Scaling with Step Scaling Policy in Pulumi?

I'm trying to autoscale Fargate Service in AWS ECS based on CloudWatch Alarm (Namespace - AWS/SQS, Metric name - ApproximateNumberOfMessagesVisible). I managed to do that in the AWS Console but not via code (in Pulumi).

My suggestion for code is below:

const vpc = new awsx.ec2.Vpc("vpc", {
  subnets: [{ type: "public" }],
});

const my_cluster = new awsx.ecs.Cluster("my-cluster", { vpc });

const task = new awsx.ecs.FargateTaskDefinition(...)

const my_fargateService = new awsx.ecs.FargateService(
  "my-fargateService",
  {
    cluster: my_cluster,
    taskDefinition: task,
    desiredCount: 0,
  }
);

const sqs_queue = new aws.sqs.Queue(
  "fargateServiceQueque"
);
const autoscaling_Policy1 = new aws.autoscaling.Policy("autoscaling_Policy1", {
  policyType: "StepScaling",
  adjustmentType: "ExactCapacity",
  stepAdjustments: [{
    metricIntervalUpperBound: 1,
    scalingAdjustment: 0
  }],
  // I think problem here
  autoscalingGroupName: autoScalingGroupFromFargateService.name // ???
});
const sqs_less_than_1 = new aws.cloudwatch.MetricAlarm("sqs_less_than_1_message_visible", {
  comparisonOperator: "LessThanThreshold",
  evaluationPeriods: "2",
  metricName: "approximateNumberOfMessagesVisible",
  namespace: "AWS/SQS",
  period: "120",
  statistic: "Maximum",
  threshold: "1",
  dimensions: {
      QueueName: sqs_queue.name,
  },
  alarmDescription: "This metric monitors number of messages in sqs queue",
  alarmActions: [] // I think it should be -> [autoscaling_Policy1.arn],
});

The problem - I don't know how to retrieve auto-scaling group ("autoScalingGroupFromFargateService.name") from my_fargateService.

In AWS Console I do that as shown on images below: enter image description here enter image description here

And I'm getting this result: enter image description here

Upvotes: 0

Views: 781

Answers (1)

Tymofii
Tymofii

Reputation: 1

To set up autoscaling for ECS Fargate you can use Pulumi aws.appautoscaling(docs).

Upvotes: 0

Related Questions