Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS-CDK ECS Service Step AutoScaling Error #1837

Closed
deromka opened this issue Feb 21, 2019 · 4 comments
Closed

AWS-CDK ECS Service Step AutoScaling Error #1837

deromka opened this issue Feb 21, 2019 · 4 comments
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling bug This issue is a bug.

Comments

@deromka
Copy link

deromka commented Feb 21, 2019

AWS-CDK Version - 0.22.0

Trying to setup the ECS Service Step AutoScaling as defined here

When deploying getting the following error:

1/44 | 2:29:14 PM | CREATE_FAILED        | AWS::ApplicationAutoScaling::ScalingPolicy  | ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/UpperPolicy (ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicyD9DB0A83) Either ScalingTargetId or all three of [ResourceId, ScalableDimension, ServiceNamespace] must be specified
       new StepScalingAction (/Users/user/devel/project/node_modules/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.js:18:26)
       \_ new StepScalingPolicy (/Users/user/devel/project/node_modules/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-policy.js:52:32)
       \_ ScalableTarget.scaleOnMetric (/Users/user/devel/project/node_modules/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.js:66:16)
       \_ ScalableTaskCount.doScaleOnMetric (/Users/user/devel/project/node_modules/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.js:42:21)
       \_ ScalableTaskCount.scaleOnMetric (/Users/user/devel/project/node_modules/@aws-cdk/aws-ecs/lib/base/scalable-task-count.js:18:22)
       \_ EcsServicesAndTasksConstruct.setupServiceAutoScaling (/Users/user/devel/project/dist/lib/constructs/ecs-services-and-tasks-construct.js:83:24)
       \_ /Users/user/devel/project/dist/lib/constructs/ecs-services-and-tasks-construct.js:56:26
       \_ Array.map (<anonymous>)
       \_ new EcsServicesAndTasksConstruct (/Users/user/devel/project/dist/lib/constructs/ecs-services-and-tasks-construct.js:47:39)
       \_ SmsApplicationStack.deployDRMaaSOnECS (/Users/user/devel/project/dist/lib/stacks/app-stack.js:203:23)
       \_ new SmsApplicationStack (/Users/user/devel/project/dist/lib/stacks/app-stack.js:47:40)
       \_ Object.<anonymous> (/Users/user/devel/project/dist/lib/app/sms-app.js:14:27)
       \_ Module._compile (internal/modules/cjs/loader.js:689:30)
       \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
       \_ Module.load (internal/modules/cjs/loader.js:599:32)
       \_ tryModuleLoad (internal/modules/cjs/loader.js:538:12)
       \_ Function.Module._load (internal/modules/cjs/loader.js:530:3)
       \_ Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
       \_ startup (internal/bootstrap/node.js:283:19)
       \_ bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

My code snippet:

setupServiceAutoScaling(name : string, service : Ec2Service, props : MyProps)
    {
        const serviceScaling = service.autoScaleTaskCount({
            minCapacity: props.ecsMinContainerCount,
            maxCapacity: props.ecsMaxContainerCount
        })

        serviceScaling.scaleOnMetric(name + 'StepCpuScaling', {
            metric: service.metricCpuUtilization(),
            scalingSteps:[
                { upper: 30, change: -1 },
                { lower: 60, change: +1 }
            ],
            adjustmentType: autoscaling.AdjustmentType.ChangeInCapacity,
        })
}

Generated CF template fragment:

ECSMyServiceTaskCountTargetMyServiceStepCpuScalingLowerPolicy6D568037:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: drmaasromanappdev550026ECSMyServiceTaskCountTargetMyServiceStepCpuScalingLowerPolicyB5BEEEF9
      PolicyType: StepScaling
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        MetricAggregationType: Average
        StepAdjustments:
          - MetricIntervalUpperBound: 0
            ScalingAdjustment: -1
    Metadata:
      aws:cdk:path: APP/ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/LowerPolicy/Resource
  ECSMyServiceTaskCountTargetMyServiceStepCpuScalingLowerAlarmD5D408D8:
    Type: AWS::CloudWatch::Alarm
    Properties:
      ComparisonOperator: LessThanOrEqualToThreshold
      EvaluationPeriods: 1
      Threshold: 30
      AlarmActions:
        - Ref: ECSMyServiceTaskCountTargetMyServiceStepCpuScalingLowerPolicy6D568037
      AlarmDescription: Lower threshold scaling alarm
      Dimensions:
        - Name: ClusterName
          Value:
            Fn::ImportValue: StackName:ecsEcsClusterClusterName3A20C485
        - Name: ServiceName
          Value:
            Fn::GetAtt:
              - ECSMyServiceService9B5D7DD3
              - Name
      MetricName: CPUUtilization
      Namespace: AWS/ECS
      Period: 60
      Statistic: Average
    Metadata:
      aws:cdk:path: APP/ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/LowerAlarm/Resource
  ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicyD9DB0A83:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: drmaasromanappdev550026ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicy13DD87BD
      PolicyType: StepScaling
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        MetricAggregationType: Average
        StepAdjustments:
          - MetricIntervalLowerBound: 0
            ScalingAdjustment: 1
    Metadata:
      aws:cdk:path: APP/ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/UpperPolicy/Resource
  ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperAlarmC120A764:
    Type: AWS::CloudWatch::Alarm
    Properties:
      ComparisonOperator: GreaterThanOrEqualToThreshold
      EvaluationPeriods: 1
      Threshold: 60
      AlarmActions:
        - Ref: ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicyD9DB0A83
      AlarmDescription: Upper threshold scaling alarm
      Dimensions:
        - Name: ClusterName
          Value:
            Fn::ImportValue: StackName:ecsEcsClusterClusterName3A20C485
        - Name: ServiceName
          Value:
            Fn::GetAtt:
              - ECSMyServiceService9B5D7DD3
              - Name
      MetricName: CPUUtilization
      Namespace: AWS/ECS
      Period: 60
      Statistic: Average
    Metadata:
      aws:cdk:path: APP/ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/UpperAlarm/Resource

It seems that the ScalingPolicy missing some essential parameters:
Either ScalingTargetId or all three of [ResourceId, ScalableDimension, ServiceNamespace] must be specified

ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicyD9DB0A83:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: drmaasromanappdev550026ECSMyServiceTaskCountTargetMyServiceStepCpuScalingUpperPolicy13DD87BD
      PolicyType: StepScaling
      StepScalingPolicyConfiguration:
        AdjustmentType: ChangeInCapacity
        MetricAggregationType: Average
        StepAdjustments:
          - MetricIntervalLowerBound: 0
            ScalingAdjustment: 1
    Metadata:
      aws:cdk:path: APP/ECS/MyService/TaskCount/Target/MyServiceStepCpuScaling/UpperPolicy/Resource
@rix0rrr rix0rrr added bug This issue is a bug. @aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling labels Feb 22, 2019
@RomainMuller
Copy link
Contributor

Are you able to try to upgrade your project to the latest CDK (0.24.1 as of writing) and see if you still have the same problem?

@piradeepk
Copy link
Contributor

This is still an issue, using the latest version of the CDK (0.30.0)

@piradeepk
Copy link
Contributor

piradeepk commented May 10, 2019

Pending PR review: 2522

@piradeepk
Copy link
Contributor

Fix has been merged and issue has been resolved.

@rix0rrr rix0rrr closed this as completed Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants