Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

aws-cdk-lib/aws-events: UPDATE_ROLLBACK_COMPLETE: Parameter ScheduleExpression is not valid #27618

Open
tmmvn opened this issue Oct 19, 2023 · 1 comment
Labels
@aws-cdk/aws-scheduler Related to the AWS Scheduler service bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@tmmvn
Copy link
Contributor

tmmvn commented Oct 19, 2023

Describe the bug

It seems events.Schedule.expression passed as schedule for new events.Rule is not validated until deployment.

Expected Behavior

Having an invalid schedule expression is caught at synthesis time instead of producing a broken template.

Current Behavior

The stack synthesizes a broken CloudFormation template that fails to deploy.

Reproduction Steps

import cdk from "aws-cdk-lib"
import lambda from "aws-cdk-lib/aws-lambda"
import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources'
import * as targets from 'aws-cdk-lib/aws-events-targets'
import * as events from 'aws-cdk-lib/aws-events'

const methodProps = {
      architecture: lambda.Architecture.ARM_64,
      code: lambda.Code.fromAsset("./src/"), // Place some index.js file in src folder
      functionName: "index",
      handler: "index.handler",
      layers: [],
      memorySize: 1536,
      runtime: lambda.Runtime.NODEJS_18_X,
      timeout: cdk.Duration.minutes(10)
    }
const handler = new lambda.Function(this, "index", methodProps)
const eventRule = new events.Rule(this, 'ScheduleRule', {
      schedule: events.Schedule.expression('cron(0/10 * ? * *)') // Adding one * or such in the end will make this valid
    })
 eventRule.addTarget(new targets.LambdaFunction(handler))

Possible Solution

I saw another issue that mentioned the expression's purpose might be to allow using new patterns before they are added to e.g. Schedule.cron. So either this can be decided to be by design, in which case some extra note on the function that the deployment is validated at runtime instead of synthesis time could be added. Alternatively, if it is decided that a successful synthesis should produce a functioning template, some validation functionality for the expression is needed.

The validation and allowing a fallback could probably coexist: validate against currently known expressions, and create an option in e.g. cdk.json context to allow unvalidated, or give a prompt / warning etc. if an expression falls through validation without hitting anything.

Additional Information/Context

Use case here is using environment variable for the expression to allow development, staging, and production lambdas to run at different intervals e.g. more frequent during development vs less frequent in production.

const eventRule = new events.Rule(this, parentId + '-scheduleRule', {
      schedule: events.Schedule.expression(process.env.SCHEDULE)
    })
    eventRule.addTarget(new targets.LambdaFunction(handler))

CDK CLI Version

2.101.1 (build 16ddad1)

Framework Version

No response

Node.js Version

v18.18.2

OS

macOS 14.0

Language

TypeScript

Language Version

No response

Other information

This touches a little on issue 7514. They seemed to have the same missing final value and got the same error during deployment. They switched their approach as the error message did not make it clear why the expression failed (first used empty, then a rate).

@tmmvn tmmvn added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 19, 2023
@github-actions github-actions bot added the @aws-cdk/aws-scheduler Related to the AWS Scheduler service label Oct 19, 2023
@pahud
Copy link
Contributor

pahud commented Oct 20, 2023

Yes we should validate this prop in CDK before deployment.

scheduleExpression: this.scheduleExpression,

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-scheduler Related to the AWS Scheduler service bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants