aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.33k stars 3.76k forks source link

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

Open garysassano opened 2 weeks ago

garysassano commented 2 weeks ago

Describe the bug

Ambiguous Schedule import causing inconsistent behavior

There seems to be an issue with the Schedule import used in scaleOnSchedule. Depending on which AWS CDK library the Schedule class is imported from, the code exhibits different behavior:

Expected Behavior

The Schedule import should be unambiguous, and the code should function consistently regardless of which AWS CDK library it is imported from.

Current Behavior

You may import the wrong Schedule without noticing until deployment.

Reproduction Steps

Use the following code snippet:

const scalableFunction = new NodejsFunction(this, "ScalableFunction", {
  functionName: "scalable-function",
  entry: join(__dirname, "..", "functions", "scalable", "index.ts"),
  runtime: Runtime.NODEJS_20_X,
  architecture: Architecture.ARM_64,
  memorySize: 1024,
  timeout: Duration.minutes(5),
  loggingFormat: LoggingFormat.JSON,
});

const scalableFunctionAlias = new Alias(this, "ScalableFunctionAlias", {
  aliasName: "live",
  version: scalableFunction.currentVersion,
});

scalableFunctionAlias
  .addAutoScaling({
    minCapacity: 1,
    maxCapacity: 10,
  })
  .scaleOnSchedule("ScaleUpInMorning", {
    schedule: Schedule.cron({ hour: "3", minute: "30" }), // Change the import to test different scenarios
    minCapacity: 5,
  });

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.145.0

Framework Version

No response

Node.js Version

20.13.1

OS

Ubuntu 22.04.3 LTS

Language

TypeScript

Language Version

No response

Other information

No response

garysassano commented 2 weeks ago

Weirdly enough, it looks like the only module that didn't work for me is present as a docs example HERE.

image