Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
garysassano opened this issue Jun 10, 2024 · 2 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@garysassano
Copy link

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:

  • import { Schedule } from "aws-cdk-lib/aws-applicationautoscaling": Works
  • import { Schedule } from "aws-cdk-lib/aws-events": Works
  • import { Schedule } from "aws-cdk-lib/aws-autoscaling": Fails

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 garysassano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 10, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jun 10, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 10, 2024
@khushail khushail self-assigned this Jun 10, 2024
@garysassano
Copy link
Author

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

image

@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-reproduction This issue needs reproduction. labels Jul 1, 2024
@khushail
Copy link
Contributor

khushail commented Jul 3, 2024

Hi @garysassano , thanks for reporting this. I agree that it should behave same irrespective of which import is used.

However upon verification, I noticed that the generated cron() schedule should be synthesized to this
which deploys successfully -

"Schedule": "cron(30 3 * * ? *)",

which is uniformly implemented in aws-events and aws-applicationautoscaling as seen here -

public readonly expressionString: string = `cron(${minute} ${hour} ${day} ${month} ${weekDay} ${year})`;

public readonly expressionString: string = `cron(${minute} ${hour} ${day} ${month} ${weekDay} ${year})`;

but the return expression in case of aws-autoscaling is different -

public readonly expressionString: string = `${minute} ${hour} ${day} ${month} ${weekDay}`;

which generates this expression in Synthesized template

"Schedule": "30 3 * * *"

which fails eventually during deployment.

@khushail khushail added p3 effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jul 3, 2024
@khushail khushail removed their assignment Jul 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p3
Projects
None yet
Development

No branches or pull requests

2 participants