José Ribeiro
José Ribeiro

Reputation: 13

ECS Service not using the second capacity provider

I'm using terraform to deploy an ECS service. What I'm trying to do is to have a mix with capacity providers that will deploy on-demand and spot instances. Based on what I have, the capacity provider with the auto scaling group that manages spot instances is not working and returning the following error No Container Instances were found in your capacity provider

I have the following resources:

Auto Scaling Groups

resource "aws_autoscaling_group" "asg_on_demand" {
  max_size              = 2
  min_size              = 1
}

resource "aws_autoscaling_group" "asg_spot" {
  max_size              = 1
  min_size              = 0
}

ECS Capacity providers

resource "aws_ecs_capacity_provider" "cp_spot" {
  auto_scaling_group_provider {
    auto_scaling_group_arn         = aws_autoscaling_group.asg_spot.arn
    managed_termination_protection = "ENABLED"

    managed_scaling {
      # amount of EC2 instances that should be added on scale-out
      maximum_scaling_step_size = 1
      minimum_scaling_step_size = 1
      status                    = "ENABLED"
    }
  }
}

resource "aws_ecs_capacity_provider" "cp_on_demand" {
  auto_scaling_group_provider {
    auto_scaling_group_arn         = aws_autoscaling_group.asg_on_demand.arn
    managed_termination_protection = "ENABLED"

    managed_scaling {
      maximum_scaling_step_size = 1
      minimum_scaling_step_size = 1
      status                    = "ENABLED"
    }
  }
}

ECS Service

resource "aws_ecs_service" "ecs_service" {
  desired_count                      = 3
  wait_for_steady_state              = false

  capacity_provider_strategy {
    capacity_provider = "cp_on_demand"
    base              = 1
    weight            = 1
  }

  capacity_provider_strategy {
    capacity_provider = "cp_spot"
    base              = 0
    weight            = 1
  }
}

With this configuration and from what I understand, with a desired_count = 3 (using this value just to trigger the scale out), I will have 2 on demand instances and 1 spot (based on the weight and base values)

The ASG on demand can scale out the necessary instance, but the ASG spot cannot. When I check the service events, I have the No Container Instances were found in your capacity provider error.

I'm assuming that since the ASG spot has a min size of 0, there are no instances to deploy the service. But shouldn't the capacity provider be able to create the EC2 spot instance?

Upvotes: 0

Views: 25

Answers (0)

Related Questions