Skip to content

fix(applicationautoscaling): validate schedule expression format in scaleOnSchedule#37237

Open
snese wants to merge 1 commit intoaws:mainfrom
snese:fix/issue-30502-schedule-validation
Open

fix(applicationautoscaling): validate schedule expression format in scaleOnSchedule#37237
snese wants to merge 1 commit intoaws:mainfrom
snese:fix/issue-30502-schedule-validation

Conversation

@snese
Copy link

@snese snese commented Mar 12, 2026

Description

Add runtime validation in ScalableTarget.scaleOnSchedule() to check that the schedule expression matches valid Application Auto Scaling formats: cron(...), rate(...), or at(...).

This catches the common mistake of importing Schedule from aws-cdk-lib/aws-autoscaling instead of aws-cdk-lib/aws-applicationautoscaling, which produces bare cron expressions (e.g. 30 3 * * *) that fail at deploy time with a cryptic CloudFormation error.

Closes #30502

What should reviewers focus on

  • The validation logic in scaleOnSchedule() — it skips unresolved Tokens and only checks resolved string expressions
  • The error message guides users to the correct import

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…caleOnSchedule

Add runtime validation in `ScalableTarget.scaleOnSchedule()` to check
that the schedule expression matches valid Application Auto Scaling
formats: `cron(...)`, `rate(...)`, or `at(...)`.

This catches the common mistake of importing `Schedule` from
`aws-cdk-lib/aws-autoscaling` instead of
`aws-cdk-lib/aws-applicationautoscaling`, which produces bare cron
expressions (e.g. `30 3 * * *`) that fail at deploy time.

The validation provides a clear error message guiding users to the
correct import.

Closes aws#30502
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2 labels Mar 12, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team March 12, 2026 15:22
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@snese
Copy link
Author

snese commented Mar 12, 2026

Exemption Request

This change adds a synth-time validation in ScalableTarget.scaleOnSchedule() that throws a ValidationError when an invalid schedule expression format is detected (e.g. bare cron from aws-autoscaling.Schedule instead of aws-applicationautoscaling.Schedule).

An integration test is not applicable here because:

  1. The validation throws before any CloudFormation template is synthesized — there is no template or snapshot to capture
  2. The behavior is fully covered by the unit test which verifies the error is thrown for invalid expressions
  3. Existing integration tests already cover the happy path with valid schedule expressions

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Mar 12, 2026
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-lambda): Alias.scaleOnSchedule() doesn't make clear which Schedule to use

2 participants