AWS: Is there a way to use an absolute instance weighting capacity for EC2 AutoScaling?

225 views Asked by At

In a single ECS Cluster, is there a way to use a max number of instances (of a concrete instance type) and if the limit es exceeded, start using another instance type instead?

I have 20 reserved instances (for a concrete instance type and quite expensive) that now they're unused so I want to fill them with many different ECS services tasks.

My infrastructure is composed by a single ECS Cluster that contains many different ECS services on it (using t3.micro on all of them within the same Autoscaling group).

I was wondering if I may use my reserved instances in my ECS Cluster, but in case that the load makes my infrastructure to exceed the 20 reserved instances, then start launching t3.micro instances.

As far as I understand, there's the possibility in AWS EC2 Autoscaling to set multiple instance types and a relative weighting capacity for them. But in my case I want an absolute number in the weighting capacity:

https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html

Something like:

resource "aws_autoscaling_group" "ec2_autoscaling_group" {
  name                      = var.autoscaling_group_name
  vpc_zone_identifier       = [var.subnets_ids]
  min_size                  = var.min_size
  max_size                  = var.max_size
  desired_capacity          = var.desired_size
  protect_from_scale_in     = var.protection_from_scale_in_status
  health_check_grace_period = var.asg_health_check_grace_period
  wait_for_capacity_timeout = var.asg_wait_for_capacity_timeout
  mixed_instances_policy {
    launch_template {
      launch_template_specification {
        launch_template_id = aws_launch_template.example.id
      }

      override {
        instance_type     = "r5.large"
        weighted_capacity = "20"            <-- This as an absolute number 
      }

      override {
        instance_type     = "t3.micro"
        weighted_capacity = ""              <-- Infinite number
      }
    }
  }
}

This is just a Terraform code just to show my problem.

I imagine that it would be another workaround using lambdas or multiple AutoScalingGroups but I don't know how to handle this...

0

There are 0 answers