aws / aws/aws-cdk

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

Open
#27,618 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-events bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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).

Contributor guide

Open the contributing guide

Research direction

Start at aws-events Schedule.expression and the events.Rule synthesis path, then reproduce the invalid cron expression from the issue. Compare synthesis behavior with the deployment failure and determine whether the intended outcome is validation or explicit documentation of runtime-only validation. Done means the chosen behavior is covered by the relevant checks or documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.