2

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 article). 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.

I guess I miss configured something in CNF.

Here is an example for the events of the ASG: enter image description here

CNF:

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: "10"
      VPCZoneIdentifier:
        - Fn::ImportValue:
            !Sub "${ServiceName}PrivateSubnet1"
        - Fn::ImportValue:
            !Sub "${ServiceName}PrivateSubnet2"
        - Fn::ImportValue:
            !Sub "${ServiceName}PrivateSubnet3"
      LaunchConfigurationName: !Ref 'launchConfiguration'
      MinSize: "0"
      MaxSize: "10"
      DesiredCapacity: "0"
      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} >> /etc/ecs/ecs.config
Lau
  • 1,353
  • 7
  • 26

0 Answers0