Skip to content

Commit ec18b83

Browse files
authored
docs(lambda): fix incorrect import in autoscaling example (#34989)
## Description This PR fixes issue #33593 where the Lambda autoscaling example in the documentation has an incorrect import. ### Current Behavior The example imports `Schedule` from `aws-cdk-lib/aws-autoscaling` which generates a raw cron expression (`0 8 * * *`). ### Issue When using `aws-autoscaling.Schedule.cron()`, the generated CloudFormation template contains a raw cron expression (`Schedule: 0 8 * * *`) which is incompatible with the `AWS::ApplicationAutoScaling::ScalableTarget` resource. This resource requires the cron expression to be wrapped with `cron(...)` and also needs the AWS-specific format with `?` character. ### Fix The correct import should be from `aws-cdk-lib/aws-applicationautoscaling` which generates the proper format (`Schedule: cron(0 8 * * ? *)`) required by `AWS::ApplicationAutoScaling::ScalableTarget`. fixes #33593 ### Description of how you validated changes I created a test CDK app to replicate the issue by implementing two stacks: 1. A stack using the incorrect import (`aws-autoscaling`), which generated: Schedule: 0 8 * * * 2. A stack using the correct import (aws-applicationautoscaling ), which generated: Schedule: cron(0 8 * * ? *) This confirmed that the incorrect import produces an incompatible cron expression format that would fail during CloudFormation deployment. I also verified that the test file ( packages/aws-cdk-lib/aws-lambda/test/integ.autoscaling.lit.ts ) was already using the correct import, which further confirms this is the right approach. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7aff4dc commit ec18b83

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/aws-cdk-lib/aws-lambda/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ const version = fn.currentVersion;
11771177
You can use Application AutoScaling to automatically configure the provisioned concurrency for your functions. AutoScaling can be set to track utilization or be based on a schedule. To configure AutoScaling on a function alias:
11781178

11791179
```ts
1180-
import * as autoscaling from 'aws-cdk-lib/aws-autoscaling';
1180+
import * as appscaling from 'aws-cdk-lib/aws-applicationautoscaling';
11811181

11821182
declare const fn: lambda.Function;
11831183
const alias = fn.addAlias('prod');
@@ -1192,7 +1192,7 @@ as.scaleOnUtilization({
11921192

11931193
// Configure Scheduled Scaling
11941194
as.scaleOnSchedule('ScaleUpInTheMorning', {
1195-
schedule: autoscaling.Schedule.cron({ hour: '8', minute: '0'}),
1195+
schedule: appscaling.Schedule.cron({ hour: '8', minute: '0'}),
11961196
minCapacity: 20,
11971197
});
11981198
```

0 commit comments

Comments
 (0)