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

fix(autoscaling): cooldown cannot be set with step scaling actions #30150

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/aws-cdk-lib/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ export class Method extends Resource {
// be applied to COGNITO_USER_POOLS AuthorizationType.
const defaultScopes = options.authorizationScopes ?? defaultMethodOptions.authorizationScopes;
const authorizationScopes = authorizationTypeOption === AuthorizationType.COGNITO ? defaultScopes : undefined;
Annotations.of(this).addWarningV2('@aws-cdk/aws-apigateway:invalidAuthScope', '\'AuthorizationScopes\' can only be set when \'AuthorizationType\' sets \'COGNITO_USER_POOLS\'. Default to ignore the values set in \'AuthorizationScopes\'.');
if (authorizationTypeOption !== AuthorizationType.COGNITO && defaultScopes) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-apigateway:invalidAuthScope', '\'AuthorizationScopes\' can only be set when \'AuthorizationType\' sets \'COGNITO_USER_POOLS\'. Default to ignore the values set in \'AuthorizationScopes\'.');
}

if (Authorizer.isAuthorizer(authorizer)) {
authorizer._attachToApi(this.api);
Expand Down
11 changes: 9 additions & 2 deletions packages/aws-cdk-lib/aws-autoscaling/lib/step-scaling-action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Construct } from 'constructs';
import { IAutoScalingGroup } from './auto-scaling-group';
import { CfnScalingPolicy } from './autoscaling.generated';
import { Duration, Lazy } from '../../core';
import { Annotations, Duration, Lazy } from '../../core';

/**
* Properties for a scaling policy
Expand All @@ -16,6 +16,7 @@ export interface StepScalingActionProps {
* Period after a scaling completes before another scaling activity can start.
*
* @default The default cooldown configured on the AutoScalingGroup
* @deprecated cooldown is not valid with step scaling action
*/
readonly cooldown?: Duration;

Expand Down Expand Up @@ -71,10 +72,16 @@ export class StepScalingAction extends Construct {
constructor(scope: Construct, id: string, props: StepScalingActionProps) {
super(scope, id);

// Specify cooldown property in StepScaling policy type is ineffective and may cause deployment failure
// in certain regions. We can't simply remove the property since it break existing users. Since setting
// this value is ineffective, we can safely ignore the value of this property with a warning.
if (props.cooldown && props.cooldown.toSeconds().toString()) {
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved
Annotations.of(this).addWarningV2('@aws-cdk/aws-autoscaling:cooldownOnStepScaling', '\'Cooldown\' is valid only if the policy type is SimpleScaling. Default to ignore the values set.');
}

const resource = new CfnScalingPolicy(this, 'Resource', {
policyType: 'StepScaling',
autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
cooldown: props.cooldown && props.cooldown.toSeconds().toString(),
estimatedInstanceWarmup: props.estimatedInstanceWarmup && props.estimatedInstanceWarmup.toSeconds(),
adjustmentType: props.adjustmentType,
minAdjustmentMagnitude: props.minAdjustmentMagnitude,
Expand Down
22 changes: 22 additions & 0 deletions packages/aws-cdk-lib/aws-autoscaling/test/scaling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ describe('scaling', () => {
});
});

test('setting cooldown on step scaling is ineffective', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const autoScalingGroup = new autoscaling.AutoScalingGroup(stack, 'ASG', {
minCapacity: 1,
maxCapacity: 100,
instanceType: new ec2.InstanceType('t-1000.macro'),
machineImage: new ec2.AmazonLinuxImage(),
vpc,
});
new autoscaling.StepScalingAction(stack, 'Action', {
autoScalingGroup,
cooldown: cdk.Duration.days(1),
});

// THEN
expect(() => Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::ScalingPolicy', {
CoolDown: undefined,
})).toThrow(/Template has 1 resources with type AWS::AutoScaling::ScalingPolicy, but none match as expected/);
});

test('step scaling', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading