-
Notifications
You must be signed in to change notification settings - Fork 4k
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
events: events.Schedule.expression does not work with cron expressions #32753
Comments
@datamystic Good morning. Somehow, I'm unable to reproduce the issue. Used below code: import * as cdk from 'aws-cdk-lib';
import * as redshiftserverless from 'aws-cdk-lib/aws-redshiftserverless'
import * as events from 'aws-cdk-lib/aws-events';
import * as sqs from 'aws-cdk-lib/aws-sqs';
import * as targets from 'aws-cdk-lib/aws-events-targets';
export class CdktestStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const workgroup = new redshiftserverless.CfnWorkgroup(this, 'RedshiftWorkgroup', {
workgroupName: 'TestRedshiftWorkgroup'
});
const rule5MinuteRate = new events.Rule(this, '5MinuteRateRule', {
schedule: events.Schedule.rate(cdk.Duration.minutes(5)),
});
const rule1MinuteRate = new events.Rule(this, '1MinuteRateRule', {
schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
});
const ruleCron1 = new events.Rule(this, 'CronRule1', {
schedule: events.Schedule.cron({
minute: '*',
hour: '*',
day: '*',
month: '*',
//weekDay: '?',
year: '*'
}),
});
const ruleCron2 = new events.Rule(this, 'CronRule2', {
schedule: events.Schedule.cron({
minute: '0',
hour: '50',
day: '0,6,12,18',
month: '*',
//weekDay: '?',
year: '*'
}),
});
const dlq = new sqs.Queue(this, 'DeadLetterQueue');
const target = new targets.RedshiftQuery(workgroup.attrWorkgroupWorkgroupArn, {
database: 'dev',
deadLetterQueue: dlq,
sql: ['SELECT * FROM foo','SELECT * FROM baz'],
})
rule5MinuteRate.addTarget(target);
rule1MinuteRate.addTarget(target);
ruleCron1.addTarget(target);
ruleCron2.addTarget(target);
}
} This synthesizes successfully to below CFN template: Resources:
RedshiftWorkgroup:
Type: AWS::RedshiftServerless::Workgroup
...
5MinuteRateRuleD8FB2596:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: rate(5 minutes)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- RedshiftWorkgroup
- Workgroup.WorkgroupArn
DeadLetterConfig:
Arn:
Fn::GetAtt:
- DeadLetterQueue9F481546
- Arn
Id: Target0
RedshiftDataParameters:
Database: dev
Sqls:
- SELECT * FROM foo
- SELECT * FROM baz
RoleArn:
Fn::GetAtt:
- 5MinuteRateRuleEventsRoleC75E085E
- Arn
Metadata:
aws:cdk:path: CdktestStack/5MinuteRateRule/Resource
5MinuteRateRuleEventsRoleC75E085E:
Type: AWS::IAM::Role
Properties:
...
5MinuteRateRuleEventsRoleDefaultPolicy7BB6A11E:
Type: AWS::IAM::Policy
Properties:
...
1MinuteRateRule874DCF22:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: rate(1 minute)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- RedshiftWorkgroup
- Workgroup.WorkgroupArn
DeadLetterConfig:
Arn:
Fn::GetAtt:
- DeadLetterQueue9F481546
- Arn
Id: Target0
RedshiftDataParameters:
Database: dev
Sqls:
- SELECT * FROM foo
- SELECT * FROM baz
RoleArn:
Fn::GetAtt:
- 1MinuteRateRuleEventsRoleC88407F2
- Arn
Metadata:
aws:cdk:path: CdktestStack/1MinuteRateRule/Resource
1MinuteRateRuleEventsRoleC88407F2:
Type: AWS::IAM::Role
Properties:
...
1MinuteRateRuleEventsRoleDefaultPolicy25A34B6E:
Type: AWS::IAM::Policy
Properties:
...
CronRule1E407A55B:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: cron(* * * * ? *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- RedshiftWorkgroup
- Workgroup.WorkgroupArn
DeadLetterConfig:
Arn:
Fn::GetAtt:
- DeadLetterQueue9F481546
- Arn
Id: Target0
RedshiftDataParameters:
Database: dev
Sqls:
- SELECT * FROM foo
- SELECT * FROM baz
RoleArn:
Fn::GetAtt:
- CronRule1EventsRole1AADBDF2
- Arn
Metadata:
aws:cdk:path: CdktestStack/CronRule1/Resource
CronRule1EventsRole1AADBDF2:
Type: AWS::IAM::Role
Properties:
...
CronRule1EventsRoleDefaultPolicy19EAA4A5:
Type: AWS::IAM::Policy
Properties:
...
CronRule29EC7AECF:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: cron(0 50 0,6,12,18 * ? *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- RedshiftWorkgroup
- Workgroup.WorkgroupArn
DeadLetterConfig:
Arn:
Fn::GetAtt:
- DeadLetterQueue9F481546
- Arn
Id: Target0
RedshiftDataParameters:
Database: dev
Sqls:
- SELECT * FROM foo
- SELECT * FROM baz
RoleArn:
Fn::GetAtt:
- CronRule2EventsRoleBEB739EA
- Arn
Metadata:
aws:cdk:path: CdktestStack/CronRule2/Resource
CronRule2EventsRoleBEB739EA:
Type: AWS::IAM::Role
Properties:
...
CronRule2EventsRoleDefaultPolicy6801243E:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
...
DeadLetterQueue9F481546:
Type: AWS::SQS::Queue
... If you are getting error Please confirm:
Thanks, Thanks, |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Ah, I think the error must be me. I'm sure I read somewhere that the cron expression can be provided as a string - which is where I had issues. In your sample above you are not doing this, so I assume that feature does not exist? |
@datamystic The CDK L2 construct's aws_events.Schedule.cron(options) doesn't have any overload that accepts Thanks, |
Thanks @ashishdhingra - it would be great if it accepted a string cron expression or rate expression. |
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
Event Bridge rules do not parse any cron expressions correctly, and some rate expressions.
Some rate strings work correctly e.g.:
rate(5 minutes)
but this does not:
rate(1 minutes)
Similar errors occur for the expected 6-field cron expressions e.g.:
cron(* * * * ? *)
cron(0 50 0,6,12,18 * ? *)
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
The expressions should be parsed correctly.
Current Behavior
Resource handler returned message: "Parameter ScheduleExpression is not valid. (Service: EventBridge, Status Code: 400, Request ID: 80fb7dec-5fcc-4c64-bd98-229b64c4c09f)" (RequestToken: 2195b1a9-2f62-ed3c-4395-c0ea64a323e8, HandlerErrorCode: GeneralServiceException)
Reproduction Steps
import * as events from 'aws-cdk-lib/aws-events';
.
.
.
.
cronRule( logGroup : cloudwatch.LogGroup, name : string, website : string, log_stream : string, cron_schedule : string )
{
}
}
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.174.0 (build 9604329)
Framework Version
No response
Node.js Version
20.11.0
OS
Windows 10
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: