diff --git a/libs/wingsdk/src/target-awscdk/schedule.ts b/libs/wingsdk/src/target-awscdk/schedule.ts index 55d4bc7f700..5a149527eea 100644 --- a/libs/wingsdk/src/target-awscdk/schedule.ts +++ b/libs/wingsdk/src/target-awscdk/schedule.ts @@ -38,15 +38,11 @@ export class Schedule extends cloud.Schedule { let cronOpt: { [k: string]: string } = { minute: cronArr[0], hour: cronArr[1], + day: cronArr[2], month: cronArr[3], + weekDay: cronArr[4], year: "*", }; - if (cronArr[2] !== "?") { - cronOpt.day = cronArr[2]; - } - if (cronArr[4] !== "?") { - cronOpt.weekDay = cronArr[4]; - } this.scheduleExpression = EventSchedule.cron(cronOpt); } else { diff --git a/libs/wingsdk/test/target-awscdk/schedule.test.ts b/libs/wingsdk/test/target-awscdk/schedule.test.ts index b61cccc473f..0165dc9b50d 100644 --- a/libs/wingsdk/test/target-awscdk/schedule.test.ts +++ b/libs/wingsdk/test/target-awscdk/schedule.test.ts @@ -139,3 +139,17 @@ test("schedule with rate less than 1 minute", () => { }) ).toThrow("rate can not be set to less than 1 minute."); }); + +test("cron with Day-of-month and Day-of-week setting with *", () => { + // GIVEN + const app = new awscdk.App({ outdir: mkdtemp(), ...CDK_APP_OPTS }); + + // THEN + expect(() => + Schedule._newSchedule(app, "Schedule", { + cron: "0/1 * * * *", + }) + ).toThrow( + "cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other" + ); +}); \ No newline at end of file