fix(autoscaling): StepScalingPolicy emits spurious cooldown deprecation warning#37836
fix(autoscaling): StepScalingPolicy emits spurious cooldown deprecation warning#37836Zelys-DFKH wants to merge 1 commit into
StepScalingPolicy emits spurious cooldown deprecation warning#37836Conversation
…cation warning
Every StepScalingPolicy (and every scaleOnMetric call) was printing two
JSII deprecation warnings for StepScalingActionProps#cooldown during
synthesis even when the user never set that property. The key was always
present in the props object (with value undefined), and JSII's generated
checker uses key-existence ('cooldown' in p) not a value test.
Fix: use conditional spread so the key is absent when cooldown is unset.
The warning fires correctly when cooldown is explicitly passed.
No CloudFormation output changes. StepScalingAction already discards
the cooldown value and does not forward it to CfnScalingPolicy.
Fixes aws#37833
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.
✅ A exemption request has been requested. Please wait for a maintainer's review.
StepScalingPolicy emits spurious cooldown deprecation warning
|
Exemption Request This fix suppresses a spurious JSII deprecation warning that fires during synthesis even when the user never sets the There are no CloudFormation output changes: |
Issue #37833
Fixes #37833
Reason for this change
Every
StepScalingPolicy(and every call toAutoScalingGroup.scaleOnMetric) prints two JSII deprecation warnings forStepScalingActionProps#cooldownduring synthesis, even when the user never set that property. In a stack with many step-scaled groups, this floods build output and buries legitimate deprecation signals.The root cause:
StepScalingPolicyunconditionally writescooldown: props.cooldowninto the props passed toStepScalingAction, so the key is always present even when the value isundefined. JSII's generated deprecation checker uses a key-existence test ('cooldown' in p) rather than a value test, so the warning fires whenever the key appears, regardless of its value.Description of changes
In
packages/aws-cdk-lib/aws-autoscaling/lib/step-scaling-policy.ts, replacedcooldown: props.cooldownwith a conditional spread in both thelowerActionandupperActionconstructor calls:When
cooldownis not set, the key is absent from the props object. The JSII key-existence check returns false and no warning fires. When the user explicitly passescooldown, it is still forwarded and the deprecation warning fires correctly.No CloudFormation output changes.
StepScalingActionalready discards thecooldownvalue and does not pass it toCfnScalingPolicy.Description of how you validated changes
Added two tests to
packages/aws-cdk-lib/aws-autoscaling/test/scaling.test.ts:scaleOnMetric without cooldown does not emit cooldown deprecation warning— verifies no@aws-cdk/aws-autoscaling:cooldownOnStepScalingCDK annotation is added to the stack.scaleOnMetric with cooldown emits cooldown deprecation warning— verifies the annotation is present whencooldownis explicitly set, confirming the intentional deprecation path is preserved.One caveat: JSII's key-existence check (
'cooldown' in p) only runs in compiled output, not in the ts-jest environment. The tests above cover the related CDK annotation behavior (StepScalingAction'sif (props.cooldown)guard). The fix can be verified end-to-end by runningcdk synthon the reproduction case in the issue and confirming the warnings no longer appear.All 20 tests in
scaling.test.tspass.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license