title: Cluster scaling group instantly desires 2 instances without any task running on the specified capacity provider
body: <p>I have ECS cluster, which already uses fargate as capacity provider. With fargate everything works fine. However, now I want to add an ASG as an additional capacity provider. As instances I want to use p2.xlarge and my tasks run very infrequent, thus I want to scale the instances to 0, when no task is placed (This should be possible according to this <a href="https://aws.amazon.com/blogs/aws/aws-ecs-cluster-auto-scaling-is-now-generally-available/" rel="nofollow noreferrer">article</a>). When I start up the necessary infrastructure, the Cluster scaling group instantly set the desired capacity of the ASG to 2. Aftert some time I can see that the ASG triggers a scale-in to 0, but shortly afterwards it launches 2 instances, which should not even be possible, because I set the maximum scale size to 1.</p>
  <p>I guess I miss configured something in CNF.</p>
  <p>Here is an example for the events of the ASG:
  <a href="https://i.stack.imgur.com/ZzoKX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZzoKX.png" alt="enter image description here" /></a></p>
  <p>CNF:</p>
  <pre><code>Resources:
    # ECS
    ecsCluster:
      Type: AWS::ECS::Cluster
      Properties:
        ClusterName: !Ref ClusterName
        CapacityProviders:
          - !Ref capacityProvider
        DefaultCapacityProviderStrategy:
          - Base: 1
            CapacityProvider: !Ref capacityProvider
    # Capacityas provider for inference
    capacityProvider:
      Type: AWS::ECS::CapacityProvider
      Properties:
        AutoScalingGroupProvider:
          AutoScalingGroupArn: !Ref ecsAutoScalingGroup
          ManagedTerminationProtection: ENABLED
          ManagedScaling:
            MaximumScalingStepSize: 1
            MinimumScalingStepSize: 1
            Status: ENABLED
            TargetCapacity: 90
        Name: !Sub ${ServiceName}EC2InferenceCapacityProvider
    ecsAutoScalingGroup:
      Type: AWS::AutoScaling::AutoScalingGroup
      Properties:
        AutoScalingGroupName: !Sub ${ServiceName}ASG
        Cooldown: &quot;10&quot;
        VPCZoneIdentifier:
          - Fn::ImportValue:
              !Sub &quot;${ServiceName}PrivateSubnet1&quot;
          - Fn::ImportValue:
              !Sub &quot;${ServiceName}PrivateSubnet2&quot;
          - Fn::ImportValue:
              !Sub &quot;${ServiceName}PrivateSubnet3&quot;
        LaunchConfigurationName: !Ref 'launchConfiguration'
        MinSize: &quot;0&quot;
        MaxSize: &quot;10&quot;
        DesiredCapacity: &quot;0&quot;
        HealthCheckGracePeriod: 300
        HealthCheckType: EC2
        TerminationPolicies: 
          - Default
        NewInstancesProtectedFromScaleIn: true
      UpdatePolicy:
        AutoScalingReplacingUpdate:
          WillReplace: true
    launchConfiguration:
      Type: AWS::AutoScaling::LaunchConfiguration
      Properties:
        ImageId: !Ref GpuAmi
        SecurityGroups: [!Ref ecsSecurityGroup]
        InstanceType: p2.xlarge
        IamInstanceProfile: !Ref 'EC2InstanceProfile'
        AssociatePublicIpAddress: true
        KeyName: default_dev_test_key
        InstanceMonitoring: false
        UserData:
          Fn::Base64: !Sub |
            #!/bin/bash -xe
            echo ECS_CLUSTER=${ClusterName} &gt;&gt; /etc/ecs/ecs.config
  </code></pre>