aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(autoscaling): add `simpleScaling` API

Open ppbcostelloc opened this issue 5 years ago • 8 comments

Currently the only way to create a simple scaling policy is to use the L1 CfnScalingPolicy type. In turn this makes it more difficult to create simple scaling policies that trigger off L2 alarms.

Use Case

This will make life a little easier when dealing with alarms but there may be other use cases I'm not aware of.

Proposed Solution

export interface SimpleScalingActionProps {
    adjustmentType: autoscaling.AdjustmentType;
    scalingAdjustment: number;
    cooldown: Duration;
    autoScalingGroup: autoscaling.AutoScalingGroup;
}

export class SimpleScalingAction extends Construct {
    public readonly scalingPolicyArn: string;
    constructor(scope: Construct, id: string, props: SimpleScalingActionProps) {
        super(scope, id);
        const resource = new CfnScalingPolicy(this, 'Resource', {
            policyType: 'SimpleScaling',
            autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
            cooldown: props.cooldown && props.cooldown.toSeconds().toString(),
            scalingAdjustment: props.scalingAdjustment,
            adjustmentType: props.adjustmentType,
        });

        this.scalingPolicyArn = resource.ref;
    }
}

export class SimpleScalingCloudwatchAction implements cloudwatch.IAlarmAction {
    constructor(private readonly simpleScalingAction: SimpleScalingAction) {
    }

    bind(scope: Construct, alarm: cloudwatch.IAlarm): cloudwatch.AlarmActionConfig {
        return { alarmActionArn: this.simpleScalingAction.scalingPolicyArn }
    }
}

This is a :rocket: Feature Request

ppbcostelloc avatar Dec 08 '20 19:12 ppbcostelloc

Take a look at how the application autoscaling module is use in Lambda and DynamoDB

NetaNir avatar Dec 09 '20 23:12 NetaNir

Take a look at how the application autoscaling module is use in Lambda and DynamoDB

This would be for scaling EC2 ASGs rather than serverless.

ppbcostelloc avatar Dec 10 '20 09:12 ppbcostelloc

The AutoScaling L2 library will create the required CloudWatch alarms and AutoScaling policies for you.

I might be missing something in your feature request, can you explain how would your desired API look in the AutoScaling L2 ? For example, how will it be different than the scaleOnMetric API?

NetaNir avatar Dec 10 '20 15:12 NetaNir

The key here is the PolicyType: SimpleScaling.

StepScaling and TargetTracking seem to be well supported but not SimpleScaling

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-policy.html#cfn-as-scalingpolicy-policytype

ppbcostelloc avatar Dec 10 '20 15:12 ppbcostelloc

got it.

NetaNir avatar Dec 10 '20 16:12 NetaNir

Is there any update on this?

m17kea avatar Jan 05 '22 15:01 m17kea

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Jan 05 '23 16:01 github-actions[bot]

Came here looking for this feature - still isn't present Autoscaling seems "quite hard" on EC2 with no easy access to Autoscaling metrics via the AutoScalingGroup object - information also very hard to find!

glynd avatar Aug 02 '23 14:08 glynd