From ff675c08bb1b821b464dd6fbe6d08db7503c8779 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Wed, 22 Nov 2023 00:29:40 +0900 Subject: [PATCH 01/13] feat(scheduler): add support for flexible time window --- .../@aws-cdk/aws-scheduler-alpha/README.md | 18 +++++ .../aws-scheduler-alpha/lib/schedule.ts | 56 ++++++++++++++- .../aws-cdk-scheduler-schedule.assets.json | 6 +- .../aws-cdk-scheduler-schedule.template.json | 31 ++++++++ .../test/integ.schedule.js.snapshot/cdk.out | 2 +- .../integ.schedule.js.snapshot/integ.json | 2 +- ...efaultTestDeployAssert24CB3896.assets.json | 2 +- .../integ.schedule.js.snapshot/manifest.json | 10 ++- .../test/integ.schedule.js.snapshot/tree.json | 69 +++++++++++++++--- .../test/integ.schedule.ts | 7 ++ .../aws-scheduler-alpha/test/schedule.test.ts | 71 ++++++++++++++++++- 11 files changed, 252 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index d4870ce51a5e1..8e9379a5a9382 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -227,6 +227,24 @@ const schedule = new Schedule(this, 'Schedule', { > Visit [Data protection in Amazon EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/data-protection.html) for more details. +## Configuring flexible time window + +You can configure flexible time windows by specifying the `flexibleTimeWindowMode` and `maximumWindowInMinutes` properties. +By default, the `flexibleTimeWindowMode` is set to `OFF` and this feature is disabled. + +```ts +declare const target: targets.LambdaInvoke; + +const schedule = new Schedule(this, 'Schedule', { + schedule: ScheduleExpression.rate(cdk.Duration.hours(12)), + target, + flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, + maximumWindowInMinutes: Duration.minutes(10), +}); +``` + +> Visit [Configuring flexible time windows](https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html) for more details. + ## Error-handling You can configure how your schedule handles failures, when EventBridge Scheduler is unable to deliver an event diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index bd8d1e004a43d..cbf199aaf8319 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -59,6 +59,20 @@ export interface ScheduleTargetProps { readonly retryAttempts?: number; } +/** + * FlexibleTimeWindow mode for the schedule. + */ +export enum FlexibleTimeWindowMode { + /** + * FlexibleTimeWindow is disabled. + */ + OFF = 'OFF', + /** + * FlexibleTimeWindow is enabled. + */ + FLEXIBLE = 'FLEXIBLE' +} + /** * Construction properties for `Schedule`. */ @@ -104,6 +118,7 @@ export interface ScheduleProps { /** * Indicates whether the schedule is enabled. + * * @default true */ readonly enabled?: boolean; @@ -114,6 +129,22 @@ export interface ScheduleProps { * @default - All events in Scheduler are encrypted with a key that AWS owns and manages. */ readonly key?: kms.IKey; + + /** + * Determines whether the schedule is invoked within a flexible time window. + * + * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html + * + * @default - FlexibleTimeWindowMode.OFF + */ + readonly flexibleTimeWindowMode?: FlexibleTimeWindowMode; + + /** + * The maximum time window during which the schedule can be invoked. + * + * @default - Required if flexibleTimeWindowMode is FLEXIBLE. + */ + readonly maximumWindowInMinutes?: Duration; } /** @@ -256,7 +287,7 @@ export class Schedule extends Resource implements ISchedule { const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, - flexibleTimeWindow: { mode: 'OFF' }, + flexibleTimeWindow: this.renderFlexibleTimeWindow(props.flexibleTimeWindowMode, props.maximumWindowInMinutes), scheduleExpression: props.schedule.expressionString, scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName, groupName: this.group?.groupName, @@ -306,4 +337,25 @@ export class Schedule extends Resource implements ISchedule { const isEmptyPolicy = Object.values(policy).every(value => value === undefined); return !isEmptyPolicy ? policy : undefined; } -} \ No newline at end of file + + private renderFlexibleTimeWindow( + flexibleTimeWindowMode?: FlexibleTimeWindowMode, maximumWindowInMinutes?: Duration, + ): CfnSchedule.FlexibleTimeWindowProperty { + if (!flexibleTimeWindowMode || flexibleTimeWindowMode === FlexibleTimeWindowMode.OFF) { + return { + mode: 'OFF', + }; + } + + if (!maximumWindowInMinutes) { + throw new Error('maximumWindowInMinutes must be provided when flexibleTimeWindowMode is set to FLEXIBLE'); + } + if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { + throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); + } + return { + mode: 'FLEXIBLE', + maximumWindowInMinutes: maximumWindowInMinutes.toMinutes(), + }; + } +} diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json index e8847c9f5c7ca..c3651b07ef951 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json @@ -1,7 +1,7 @@ { - "version": "34.0.0", + "version": "35.0.0", "files": { - "a512067604698fe41cacf63c82484e8e597c04456ac3f27ded0a390ca25f0908": { + "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed": { "source": { "path": "aws-cdk-scheduler-schedule.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "a512067604698fe41cacf63c82484e8e597c04456ac3f27ded0a390ca25f0908.json", + "objectKey": "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json index 4bbea65f69deb..97fd3bab45b90 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json @@ -348,6 +348,37 @@ } } } + }, + "UseFlexibleTimeWindowBF55D3ED": { + "Type": "AWS::Scheduler::Schedule", + "Properties": { + "FlexibleTimeWindow": { + "MaximumWindowInMinutes": 10, + "Mode": "FLEXIBLE" + }, + "ScheduleExpression": "rate(12 hours)", + "ScheduleExpressionTimezone": "Etc/UTC", + "State": "ENABLED", + "Target": { + "Arn": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "Input": "\"Input Text\"", + "RetryPolicy": { + "MaximumEventAgeInSeconds": 180, + "MaximumRetryAttempts": 3 + }, + "RoleArn": { + "Fn::GetAtt": [ + "Role1ABCC5F0", + "Arn" + ] + } + } + } } }, "Parameters": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/cdk.out b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/cdk.out index 2313ab5436501..c5cb2e5de6344 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"34.0.0"} \ No newline at end of file +{"version":"35.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integ.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integ.json index c1aec1a40f53f..6728e425e3c98 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "34.0.0", + "version": "35.0.0", "testCases": { "integtest-schedule/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integtestscheduleDefaultTestDeployAssert24CB3896.assets.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integtestscheduleDefaultTestDeployAssert24CB3896.assets.json index 8f8a003c1b5ba..98271e1ade15f 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integtestscheduleDefaultTestDeployAssert24CB3896.assets.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/integtestscheduleDefaultTestDeployAssert24CB3896.assets.json @@ -1,5 +1,5 @@ { - "version": "34.0.0", + "version": "35.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json index 9f07a82776a8b..8f3e03c762390 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "34.0.0", + "version": "35.0.0", "artifacts": { "aws-cdk-scheduler-schedule.assets": { "type": "cdk:asset-manifest", @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/a512067604698fe41cacf63c82484e8e597c04456ac3f27ded0a390ca25f0908.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -118,6 +118,12 @@ "data": "CustomerKmsSchedule12B1FEFE" } ], + "/aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "UseFlexibleTimeWindowBF55D3ED" + } + ], "/aws-cdk-scheduler-schedule/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json index d503798aa5ec7..c3095213e2502 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json @@ -211,7 +211,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Group", "version": "0.0.0" } }, @@ -235,7 +235,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Group", "version": "0.0.0" } }, @@ -283,7 +283,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -332,7 +332,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -381,7 +381,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -429,7 +429,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -477,7 +477,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -612,7 +612,56 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", + "version": "0.0.0" + } + }, + "UseFlexibleTimeWindow": { + "id": "UseFlexibleTimeWindow", + "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Scheduler::Schedule", + "aws:cdk:cloudformation:props": { + "flexibleTimeWindow": { + "mode": "FLEXIBLE", + "maximumWindowInMinutes": 10 + }, + "scheduleExpression": "rate(12 hours)", + "scheduleExpressionTimezone": "Etc/UTC", + "state": "ENABLED", + "target": { + "arn": { + "Fn::GetAtt": [ + "Function76856677", + "Arn" + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "Role1ABCC5F0", + "Arn" + ] + }, + "input": "\"Input Text\"", + "retryPolicy": { + "maximumEventAgeInSeconds": 180, + "maximumRetryAttempts": 3 + } + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_scheduler.CfnSchedule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-scheduler-alpha.Schedule", "version": "0.0.0" } }, @@ -651,7 +700,7 @@ "path": "integtest-schedule/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.70" + "version": "10.3.0" } }, "DeployAssert": { @@ -697,7 +746,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.70" + "version": "10.3.0" } } }, diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 51ff3089c8a5d..a05c975a79d41 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -90,6 +90,13 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { key, }); +new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { + schedule: expression, + target: target, + flexibleTimeWindowMode: scheduler.FlexibleTimeWindowMode.FLEXIBLE, + maximumWindowInMinutes: cdk.Duration.minutes(10), +}); + new IntegTest(app, 'integtest-schedule', { testCases: [stack], }); diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index 004e9934e281e..7896b33dfbea1 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -4,7 +4,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { IScheduleTarget, Schedule, ScheduleTargetConfig } from '../lib'; +import { IScheduleTarget, Schedule, ScheduleTargetConfig, FlexibleTimeWindowMode } from '../lib'; import { ScheduleExpression } from '../lib/schedule-expression'; class SomeLambdaTarget implements IScheduleTarget { @@ -128,4 +128,71 @@ describe('Schedule', () => { }, }); }); -}); \ No newline at end of file + + describe('flexibleTimeWindow', () => { + test('flexibleTimeWindow mode is set to OFF by default', () => { + // WHEN + new Schedule(stack, 'TestSchedule', { + schedule: expr, + target: new SomeLambdaTarget(func, role), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Scheduler::Schedule', { + FlexibleTimeWindow: { + Mode: 'OFF', + }, + }); + }); + + test('flexibleTimeWindow mode can be set to FLEXIBLE', () => { + // WHEN + new Schedule(stack, 'TestSchedule', { + schedule: expr, + target: new SomeLambdaTarget(func, role), + flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, + maximumWindowInMinutes: Duration.minutes(1440), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Scheduler::Schedule', { + FlexibleTimeWindow: { + Mode: 'FLEXIBLE', + MaximumWindowInMinutes: 1440, + }, + }); + }); + + test('throw error when FlexibleTimeWindowMode is FLEXIBLE and maximumWindowInMinutes not provided', () => { + expect(() => { + new Schedule(stack, 'TestSchedule', { + schedule: expr, + target: new SomeLambdaTarget(func, role), + flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, + }); + }).toThrow('maximumWindowInMinutes must be provided when flexibleTimeWindowMode is set to FLEXIBLE'); + }); + + test('throw error when maximumWindowInMinutes is more than 1440', () => { + expect(() => { + new Schedule(stack, 'TestSchedule', { + schedule: expr, + target: new SomeLambdaTarget(func, role), + flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, + maximumWindowInMinutes: Duration.minutes(1441), + }); + }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); + }); + + test('throw error when maximumWindowInMinutes is less than 1', () => { + expect(() => { + new Schedule(stack, 'TestSchedule', { + schedule: expr, + target: new SomeLambdaTarget(func, role), + flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, + maximumWindowInMinutes: Duration.minutes(0), + }); + }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); + }); + }); +}); From 85b60d49cad4f6464a848d3072723024dcbdcfd6 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Wed, 22 Nov 2023 13:23:49 +0900 Subject: [PATCH 02/13] feat(scheduler): add warning --- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index cbf199aaf8319..bd6d988f987e2 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -1,4 +1,4 @@ -import { Duration, IResource, Resource } from 'aws-cdk-lib'; +import { Annotations, Duration, IResource, Resource } from 'aws-cdk-lib'; import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; import * as kms from 'aws-cdk-lib/aws-kms'; import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler'; @@ -342,6 +342,9 @@ export class Schedule extends Resource implements ISchedule { flexibleTimeWindowMode?: FlexibleTimeWindowMode, maximumWindowInMinutes?: Duration, ): CfnSchedule.FlexibleTimeWindowProperty { if (!flexibleTimeWindowMode || flexibleTimeWindowMode === FlexibleTimeWindowMode.OFF) { + if (maximumWindowInMinutes) { + Annotations.of(this).addWarningV2('@aws-cdk/aws-scheduler:maximumWindowInMinutesIgnored', 'maximumWindowInMinutes is ignored when flexibleTimeWindowMode is not FLEXIBLE'); + } return { mode: 'OFF', }; From b71fd8e0181a448eab490dbf74776f22894f9391 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Wed, 22 Nov 2023 14:57:58 +0900 Subject: [PATCH 03/13] feat(scheduler): fix build failed --- packages/@aws-cdk/aws-scheduler-alpha/README.md | 6 +++--- .../@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index 8e9379a5a9382..9e12c9b0d6c1a 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -23,7 +23,7 @@ of millions of tasks across many AWS services without provisioning or managing u 2. **Targets**: A target is an API operation that EventBridge Scheduler calls on your behalf every time your schedule runs. EventBridge Scheduler supports two types of targets: templated targets and universal targets. Templated targets invoke common API operations across a core groups of services. For example, EventBridge Scheduler supports templated targets for invoking AWS Lambda Function or starting execution of Step Function state -machine. For API operations that are not supported by templated targets you can use customizeable universal targets. Universal targets support calling +machine. For API operations that are not supported by templated targets you can use customizable universal targets. Universal targets support calling more than 6,000 API operations across over 270 AWS services. 3. **Schedule Group**: A schedule group is an Amazon EventBridge Scheduler resource that you use to organize your schedules. Your AWS account comes with a default scheduler group. A new schedule will always be added to a scheduling group. If you do not provide a scheduling group to add to, it @@ -143,7 +143,7 @@ new Schedule(this, 'Schedule', { The `@aws-cdk/aws-scheduler-targets-alpha` module includes classes that implement the `IScheduleTarget` interface for various AWS services. EventBridge Scheduler supports two types of targets: templated targets invoke common API -operations across a core groups of services, and customizeable universal targets that you can use to call more +operations across a core groups of services, and customizable universal targets that you can use to call more than 6,000 operations across over 270 services. A list of supported targets can be found at `@aws-cdk/aws-scheduler-targets-alpha`. ### Input @@ -236,7 +236,7 @@ By default, the `flexibleTimeWindowMode` is set to `OFF` and this feature is dis declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { - schedule: ScheduleExpression.rate(cdk.Duration.hours(12)), + schedule: ScheduleExpression.rate(Duration.hours(12)), target, flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, maximumWindowInMinutes: Duration.minutes(10), diff --git a/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture index cbb0128852cb7..c3b6690b5e25b 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture @@ -8,7 +8,7 @@ import * as sqs from 'aws-cdk-lib/aws-sqs'; import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; import * as targets from '@aws-cdk/aws-scheduler-targets-alpha'; import { App, Stack, TimeZone, Duration } from 'aws-cdk-lib'; -import { ScheduleExpression, ScheduleTargetInput, ContextAttribute, Group, Schedule } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, ScheduleTargetInput, ContextAttribute, Group, Schedule, FlexibleTimeWindowMode } from '@aws-cdk/aws-scheduler-alpha'; class Fixture extends cdk.Stack { constructor(scope: Construct, id: string) { From 21c4331649d6ea4d361fa8b67009852e06ad5c45 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 24 Nov 2023 17:30:02 +0900 Subject: [PATCH 04/13] feat(scheduler): fixed for the review --- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 10 +++++----- .../@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index bd6d988f987e2..82b09e630d46c 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -67,6 +67,7 @@ export enum FlexibleTimeWindowMode { * FlexibleTimeWindow is disabled. */ OFF = 'OFF', + /** * FlexibleTimeWindow is enabled. */ @@ -142,6 +143,8 @@ export interface ScheduleProps { /** * The maximum time window during which the schedule can be invoked. * + * Must be between 1 to 1440 minutes. + * * @default - Required if flexibleTimeWindowMode is FLEXIBLE. */ readonly maximumWindowInMinutes?: Duration; @@ -342,11 +345,8 @@ export class Schedule extends Resource implements ISchedule { flexibleTimeWindowMode?: FlexibleTimeWindowMode, maximumWindowInMinutes?: Duration, ): CfnSchedule.FlexibleTimeWindowProperty { if (!flexibleTimeWindowMode || flexibleTimeWindowMode === FlexibleTimeWindowMode.OFF) { - if (maximumWindowInMinutes) { - Annotations.of(this).addWarningV2('@aws-cdk/aws-scheduler:maximumWindowInMinutesIgnored', 'maximumWindowInMinutes is ignored when flexibleTimeWindowMode is not FLEXIBLE'); - } return { - mode: 'OFF', + mode: FlexibleTimeWindowMode.OFF, }; } @@ -357,7 +357,7 @@ export class Schedule extends Resource implements ISchedule { throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); } return { - mode: 'FLEXIBLE', + mode: flexibleTimeWindowMode, maximumWindowInMinutes: maximumWindowInMinutes.toMinutes(), }; } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index 7896b33dfbea1..a1760a21b6b63 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -173,7 +173,7 @@ describe('Schedule', () => { }).toThrow('maximumWindowInMinutes must be provided when flexibleTimeWindowMode is set to FLEXIBLE'); }); - test('throw error when maximumWindowInMinutes is more than 1440', () => { + test('throw error when maximumWindowInMinutes is greater than 1440', () => { expect(() => { new Schedule(stack, 'TestSchedule', { schedule: expr, From 2a2b00d68b98b65b210cf29e2f59e8ad8997bb1f Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 24 Nov 2023 17:49:13 +0900 Subject: [PATCH 05/13] feat(scheduler): fix build --- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 82b09e630d46c..63db1713a1858 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -1,4 +1,4 @@ -import { Annotations, Duration, IResource, Resource } from 'aws-cdk-lib'; +import { Duration, IResource, Resource } from 'aws-cdk-lib'; import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; import * as kms from 'aws-cdk-lib/aws-kms'; import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler'; From 24cebc15fcf711cc2a40f84ebe6c6148629fe37c Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 24 Nov 2023 22:01:02 +0900 Subject: [PATCH 06/13] feat(scheduler): fix for the review --- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 63db1713a1858..3a956f15f186e 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -344,9 +344,11 @@ export class Schedule extends Resource implements ISchedule { private renderFlexibleTimeWindow( flexibleTimeWindowMode?: FlexibleTimeWindowMode, maximumWindowInMinutes?: Duration, ): CfnSchedule.FlexibleTimeWindowProperty { - if (!flexibleTimeWindowMode || flexibleTimeWindowMode === FlexibleTimeWindowMode.OFF) { + const mode = flexibleTimeWindowMode ?? FlexibleTimeWindowMode.OFF; + + if (mode === FlexibleTimeWindowMode.OFF) { return { - mode: FlexibleTimeWindowMode.OFF, + mode, }; } @@ -357,7 +359,7 @@ export class Schedule extends Resource implements ISchedule { throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); } return { - mode: flexibleTimeWindowMode, + mode, maximumWindowInMinutes: maximumWindowInMinutes.toMinutes(), }; } From 443fa096ca95ea5f2a09881868bafb1ba0111516 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 8 Dec 2023 21:04:32 +0900 Subject: [PATCH 07/13] feat(scheduler): refactor class --- .../@aws-cdk/aws-scheduler-alpha/README.md | 7 +- .../aws-scheduler-alpha/lib/schedule.ts | 81 ++++++++++--------- .../aws-cdk-scheduler-schedule.assets.json | 4 +- .../aws-cdk-scheduler-schedule.template.json | 7 +- .../integ.schedule.js.snapshot/manifest.json | 15 +++- .../test/integ.schedule.js.snapshot/tree.json | 13 +-- .../test/integ.schedule.ts | 3 +- .../aws-scheduler-alpha/test/schedule.test.ts | 19 +---- 8 files changed, 73 insertions(+), 76 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index 9e12c9b0d6c1a..3371b201b3007 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -229,8 +229,8 @@ const schedule = new Schedule(this, 'Schedule', { ## Configuring flexible time window -You can configure flexible time windows by specifying the `flexibleTimeWindowMode` and `maximumWindowInMinutes` properties. -By default, the `flexibleTimeWindowMode` is set to `OFF` and this feature is disabled. +You can configure flexible time windows by specifying the `flexibleTimeWindow` property. +By default, the mode of `flexibleTimeWindow` is set to `OFF` and this feature is disabled. ```ts declare const target: targets.LambdaInvoke; @@ -238,8 +238,7 @@ declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { schedule: ScheduleExpression.rate(Duration.hours(12)), target, - flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, - maximumWindowInMinutes: Duration.minutes(10), + flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.hours(10)), }); ``` diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 3a956f15f186e..587c217f1fd65 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -60,18 +60,46 @@ export interface ScheduleTargetProps { } /** - * FlexibleTimeWindow mode for the schedule. + * A time window during which EventBridge Scheduler invokes the schedule. + * + * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html */ -export enum FlexibleTimeWindowMode { +export class FlexibleTimeWindowMode { /** * FlexibleTimeWindow is disabled. */ - OFF = 'OFF', + public static OFF(): FlexibleTimeWindowMode { + return new FlexibleTimeWindowMode('OFF'); + } /** * FlexibleTimeWindow is enabled. */ - FLEXIBLE = 'FLEXIBLE' + public static FLEXIBLE(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { + if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { + throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); + } + return new FlexibleTimeWindowMode('FLEXIBLE', maximumWindowInMinutes); + } + + /** + * Determines whether the schedule is invoked within a flexible time window. + */ + public readonly mode: string; + + /** + * The maximum time window during which the schedule can be invoked. + * + * Must be between 1 to 1440 minutes. + * + * @default - Required if mode is FLEXIBLE. + */ + public readonly maximumWindowInMinutes?: Duration; + + private constructor(mode: string, maximumWindowInMinutes?: Duration) { + this.mode = mode; + this.maximumWindowInMinutes = maximumWindowInMinutes; + } } /** @@ -132,22 +160,13 @@ export interface ScheduleProps { readonly key?: kms.IKey; /** - * Determines whether the schedule is invoked within a flexible time window. + * A time window during which EventBridge Scheduler invokes the schedule. * * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html * - * @default - FlexibleTimeWindowMode.OFF + * @default FlexibleTimeWindowMode.OFF() */ - readonly flexibleTimeWindowMode?: FlexibleTimeWindowMode; - - /** - * The maximum time window during which the schedule can be invoked. - * - * Must be between 1 to 1440 minutes. - * - * @default - Required if flexibleTimeWindowMode is FLEXIBLE. - */ - readonly maximumWindowInMinutes?: Duration; + readonly flexibleTimeWindow?: FlexibleTimeWindowMode; } /** @@ -288,9 +307,14 @@ export class Schedule extends Resource implements ISchedule { this.retryPolicy = targetConfig.retryPolicy; + const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.OFF(); + const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, - flexibleTimeWindow: this.renderFlexibleTimeWindow(props.flexibleTimeWindowMode, props.maximumWindowInMinutes), + flexibleTimeWindow: { + mode: flexibleTimeWindow.mode, + maximumWindowInMinutes: flexibleTimeWindow.maximumWindowInMinutes?.toMinutes(), + }, scheduleExpression: props.schedule.expressionString, scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName, groupName: this.group?.groupName, @@ -340,27 +364,4 @@ export class Schedule extends Resource implements ISchedule { const isEmptyPolicy = Object.values(policy).every(value => value === undefined); return !isEmptyPolicy ? policy : undefined; } - - private renderFlexibleTimeWindow( - flexibleTimeWindowMode?: FlexibleTimeWindowMode, maximumWindowInMinutes?: Duration, - ): CfnSchedule.FlexibleTimeWindowProperty { - const mode = flexibleTimeWindowMode ?? FlexibleTimeWindowMode.OFF; - - if (mode === FlexibleTimeWindowMode.OFF) { - return { - mode, - }; - } - - if (!maximumWindowInMinutes) { - throw new Error('maximumWindowInMinutes must be provided when flexibleTimeWindowMode is set to FLEXIBLE'); - } - if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { - throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); - } - return { - mode, - maximumWindowInMinutes: maximumWindowInMinutes.toMinutes(), - }; - } } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json index c3651b07ef951..03dd7cb96ad07 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json @@ -1,7 +1,7 @@ { "version": "35.0.0", "files": { - "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed": { + "77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e": { "source": { "path": "aws-cdk-scheduler-schedule.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", + "objectKey": "77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json index 97fd3bab45b90..5cdf90fef2ef6 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json @@ -349,15 +349,16 @@ } } }, - "UseFlexibleTimeWindowBF55D3ED": { + "ScheduleWithTimeFrameC1C8BDCC": { "Type": "AWS::Scheduler::Schedule", "Properties": { + "EndDate": "2025-10-01T00:00:00.000Z", "FlexibleTimeWindow": { - "MaximumWindowInMinutes": 10, - "Mode": "FLEXIBLE" + "Mode": "OFF" }, "ScheduleExpression": "rate(12 hours)", "ScheduleExpressionTimezone": "Etc/UTC", + "StartDate": "2024-04-15T06:30:00.000Z", "State": "ENABLED", "Target": { "Arn": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json index 8f3e03c762390..b538734625e4c 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -118,10 +118,10 @@ "data": "CustomerKmsSchedule12B1FEFE" } ], - "/aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource": [ + "/aws-cdk-scheduler-schedule/ScheduleWithTimeFrame/Resource": [ { "type": "aws:cdk:logicalId", - "data": "UseFlexibleTimeWindowBF55D3ED" + "data": "ScheduleWithTimeFrameC1C8BDCC" } ], "/aws-cdk-scheduler-schedule/BootstrapVersion": [ @@ -135,6 +135,15 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } + ], + "UseFlexibleTimeWindowBF55D3ED": [ + { + "type": "aws:cdk:logicalId", + "data": "UseFlexibleTimeWindowBF55D3ED", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" + ] + } ] }, "displayName": "aws-cdk-scheduler-schedule" diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json index c3095213e2502..d99f1d9237516 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json @@ -616,22 +616,23 @@ "version": "0.0.0" } }, - "UseFlexibleTimeWindow": { - "id": "UseFlexibleTimeWindow", - "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow", + "ScheduleWithTimeFrame": { + "id": "ScheduleWithTimeFrame", + "path": "aws-cdk-scheduler-schedule/ScheduleWithTimeFrame", "children": { "Resource": { "id": "Resource", - "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource", + "path": "aws-cdk-scheduler-schedule/ScheduleWithTimeFrame/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::Scheduler::Schedule", "aws:cdk:cloudformation:props": { + "endDate": "2025-10-01T00:00:00.000Z", "flexibleTimeWindow": { - "mode": "FLEXIBLE", - "maximumWindowInMinutes": 10 + "mode": "OFF" }, "scheduleExpression": "rate(12 hours)", "scheduleExpressionTimezone": "Etc/UTC", + "startDate": "2024-04-15T06:30:00.000Z", "state": "ENABLED", "target": { "arn": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index a05c975a79d41..87fb31962ad6f 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -93,8 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { schedule: expression, target: target, - flexibleTimeWindowMode: scheduler.FlexibleTimeWindowMode.FLEXIBLE, - maximumWindowInMinutes: cdk.Duration.minutes(10), + flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.FLEXIBLE(cdk.Duration.minutes(10)), }); new IntegTest(app, 'integtest-schedule', { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index a1760a21b6b63..1ae8d18a84aa8 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -150,8 +150,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, - maximumWindowInMinutes: Duration.minutes(1440), + flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(1440)), }); // THEN @@ -163,23 +162,12 @@ describe('Schedule', () => { }); }); - test('throw error when FlexibleTimeWindowMode is FLEXIBLE and maximumWindowInMinutes not provided', () => { - expect(() => { - new Schedule(stack, 'TestSchedule', { - schedule: expr, - target: new SomeLambdaTarget(func, role), - flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, - }); - }).toThrow('maximumWindowInMinutes must be provided when flexibleTimeWindowMode is set to FLEXIBLE'); - }); - test('throw error when maximumWindowInMinutes is greater than 1440', () => { expect(() => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, - maximumWindowInMinutes: Duration.minutes(1441), + flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(1441)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); }); @@ -189,8 +177,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindowMode: FlexibleTimeWindowMode.FLEXIBLE, - maximumWindowInMinutes: Duration.minutes(0), + flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(0)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); From 9af2ec858b5b930bef165f9404f7b86e3c6f8a6e Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 8 Dec 2023 21:38:40 +0900 Subject: [PATCH 08/13] feat(scheduler): fix build --- packages/@aws-cdk/aws-scheduler-alpha/README.md | 4 ++-- .../@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 6 +++--- .../@aws-cdk/aws-scheduler-alpha/package.json | 2 +- .../aws-cdk-scheduler-schedule.assets.json | 4 ++-- .../aws-cdk-scheduler-schedule.template.json | 7 +++---- .../test/integ.schedule.js.snapshot/manifest.json | 15 +++------------ .../test/integ.schedule.js.snapshot/tree.json | 13 ++++++------- .../aws-scheduler-alpha/test/integ.schedule.ts | 2 +- .../aws-scheduler-alpha/test/schedule.test.ts | 6 +++--- 9 files changed, 24 insertions(+), 35 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index 3371b201b3007..f70f8f6d9240d 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -230,7 +230,7 @@ const schedule = new Schedule(this, 'Schedule', { ## Configuring flexible time window You can configure flexible time windows by specifying the `flexibleTimeWindow` property. -By default, the mode of `flexibleTimeWindow` is set to `OFF` and this feature is disabled. +By default, the mode of `flexibleTimeWindow` is set to `off` and this feature is disabled. ```ts declare const target: targets.LambdaInvoke; @@ -238,7 +238,7 @@ declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { schedule: ScheduleExpression.rate(Duration.hours(12)), target, - flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.hours(10)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.hours(10)), }); ``` diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 587c217f1fd65..7bf6f6fc5ace7 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -68,14 +68,14 @@ export class FlexibleTimeWindowMode { /** * FlexibleTimeWindow is disabled. */ - public static OFF(): FlexibleTimeWindowMode { + public static off(): FlexibleTimeWindowMode { return new FlexibleTimeWindowMode('OFF'); } /** * FlexibleTimeWindow is enabled. */ - public static FLEXIBLE(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { + public static flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); } @@ -307,7 +307,7 @@ export class Schedule extends Resource implements ISchedule { this.retryPolicy = targetConfig.retryPolicy; - const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.OFF(); + const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.off(); const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, diff --git a/packages/@aws-cdk/aws-scheduler-alpha/package.json b/packages/@aws-cdk/aws-scheduler-alpha/package.json index 78bad0bbf7413..82a0e10399e97 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/package.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/package.json @@ -116,4 +116,4 @@ "@aws-cdk/aws-scheduler-targets-alpha": "*" } } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json index 03dd7cb96ad07..c3651b07ef951 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.assets.json @@ -1,7 +1,7 @@ { "version": "35.0.0", "files": { - "77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e": { + "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed": { "source": { "path": "aws-cdk-scheduler-schedule.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e.json", + "objectKey": "fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json index 5cdf90fef2ef6..97fd3bab45b90 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/aws-cdk-scheduler-schedule.template.json @@ -349,16 +349,15 @@ } } }, - "ScheduleWithTimeFrameC1C8BDCC": { + "UseFlexibleTimeWindowBF55D3ED": { "Type": "AWS::Scheduler::Schedule", "Properties": { - "EndDate": "2025-10-01T00:00:00.000Z", "FlexibleTimeWindow": { - "Mode": "OFF" + "MaximumWindowInMinutes": 10, + "Mode": "FLEXIBLE" }, "ScheduleExpression": "rate(12 hours)", "ScheduleExpressionTimezone": "Etc/UTC", - "StartDate": "2024-04-15T06:30:00.000Z", "State": "ENABLED", "Target": { "Arn": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json index b538734625e4c..8f3e03c762390 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/77d06d03c78dc7776966b7c7ee414cc19be012ccfba5d7a9b1e425718920ab3e.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fb65b4879013f737f0239f0734927efc6501f332052f5369f0b96869471059ed.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -118,10 +118,10 @@ "data": "CustomerKmsSchedule12B1FEFE" } ], - "/aws-cdk-scheduler-schedule/ScheduleWithTimeFrame/Resource": [ + "/aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource": [ { "type": "aws:cdk:logicalId", - "data": "ScheduleWithTimeFrameC1C8BDCC" + "data": "UseFlexibleTimeWindowBF55D3ED" } ], "/aws-cdk-scheduler-schedule/BootstrapVersion": [ @@ -135,15 +135,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "UseFlexibleTimeWindowBF55D3ED": [ - { - "type": "aws:cdk:logicalId", - "data": "UseFlexibleTimeWindowBF55D3ED", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "aws-cdk-scheduler-schedule" diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json index d99f1d9237516..c3095213e2502 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.js.snapshot/tree.json @@ -616,23 +616,22 @@ "version": "0.0.0" } }, - "ScheduleWithTimeFrame": { - "id": "ScheduleWithTimeFrame", - "path": "aws-cdk-scheduler-schedule/ScheduleWithTimeFrame", + "UseFlexibleTimeWindow": { + "id": "UseFlexibleTimeWindow", + "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow", "children": { "Resource": { "id": "Resource", - "path": "aws-cdk-scheduler-schedule/ScheduleWithTimeFrame/Resource", + "path": "aws-cdk-scheduler-schedule/UseFlexibleTimeWindow/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::Scheduler::Schedule", "aws:cdk:cloudformation:props": { - "endDate": "2025-10-01T00:00:00.000Z", "flexibleTimeWindow": { - "mode": "OFF" + "mode": "FLEXIBLE", + "maximumWindowInMinutes": 10 }, "scheduleExpression": "rate(12 hours)", "scheduleExpressionTimezone": "Etc/UTC", - "startDate": "2024-04-15T06:30:00.000Z", "state": "ENABLED", "target": { "arn": { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 87fb31962ad6f..6dc0a69001e86 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -93,7 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { schedule: expression, target: target, - flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.FLEXIBLE(cdk.Duration.minutes(10)), + flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.flexible(cdk.Duration.minutes(10)), }); new IntegTest(app, 'integtest-schedule', { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index 1ae8d18a84aa8..4199853a721be 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -150,7 +150,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(1440)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1440)), }); // THEN @@ -167,7 +167,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(1441)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1441)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); }); @@ -177,7 +177,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.FLEXIBLE(Duration.minutes(0)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(0)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); From a8c279aa87be5044cab762c38687f191e7e6e609 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 8 Dec 2023 22:01:52 +0900 Subject: [PATCH 09/13] feat(code): delete new line --- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 2 +- packages/@aws-cdk/aws-scheduler-alpha/package.json | 2 +- packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 7bf6f6fc5ace7..6f89e40d14966 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -364,4 +364,4 @@ export class Schedule extends Resource implements ISchedule { const isEmptyPolicy = Object.values(policy).every(value => value === undefined); return !isEmptyPolicy ? policy : undefined; } -} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-scheduler-alpha/package.json b/packages/@aws-cdk/aws-scheduler-alpha/package.json index 82a0e10399e97..78bad0bbf7413 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/package.json +++ b/packages/@aws-cdk/aws-scheduler-alpha/package.json @@ -116,4 +116,4 @@ "@aws-cdk/aws-scheduler-targets-alpha": "*" } } -} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index 4199853a721be..f286f80875030 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -182,4 +182,4 @@ describe('Schedule', () => { }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); }); -}); +}); \ No newline at end of file From ba4630b3a39ba7eb93b45ff3227a4873118f352c Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 8 Dec 2023 22:18:06 +0900 Subject: [PATCH 10/13] feat(scheduler): change property names --- packages/@aws-cdk/aws-scheduler-alpha/README.md | 4 ++-- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 10 ++++------ .../aws-scheduler-alpha/test/integ.schedule.ts | 2 +- .../@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index f70f8f6d9240d..4b0cfc6917f7f 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -230,7 +230,7 @@ const schedule = new Schedule(this, 'Schedule', { ## Configuring flexible time window You can configure flexible time windows by specifying the `flexibleTimeWindow` property. -By default, the mode of `flexibleTimeWindow` is set to `off` and this feature is disabled. +By default, the mode of `flexibleTimeWindow` is set to `OFF` and this feature is disabled. ```ts declare const target: targets.LambdaInvoke; @@ -238,7 +238,7 @@ declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { schedule: ScheduleExpression.rate(Duration.hours(12)), target, - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.hours(10)), + flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.hours(10)), }); ``` diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index 6f89e40d14966..d514038a81564 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -61,21 +61,19 @@ export interface ScheduleTargetProps { /** * A time window during which EventBridge Scheduler invokes the schedule. - * - * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html */ export class FlexibleTimeWindowMode { /** * FlexibleTimeWindow is disabled. */ - public static off(): FlexibleTimeWindowMode { + public static Off(): FlexibleTimeWindowMode { return new FlexibleTimeWindowMode('OFF'); } /** * FlexibleTimeWindow is enabled. */ - public static flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { + public static Flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); } @@ -164,7 +162,7 @@ export interface ScheduleProps { * * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html * - * @default FlexibleTimeWindowMode.OFF() + * @default FlexibleTimeWindowMode.Off() */ readonly flexibleTimeWindow?: FlexibleTimeWindowMode; } @@ -307,7 +305,7 @@ export class Schedule extends Resource implements ISchedule { this.retryPolicy = targetConfig.retryPolicy; - const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.off(); + const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.Off(); const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 6dc0a69001e86..6d3ce3cc1df04 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -93,7 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { schedule: expression, target: target, - flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.flexible(cdk.Duration.minutes(10)), + flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.Flexible(cdk.Duration.minutes(10)), }); new IntegTest(app, 'integtest-schedule', { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index f286f80875030..eb281917365ad 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -150,7 +150,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1440)), + flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1440)), }); // THEN @@ -167,7 +167,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1441)), + flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1441)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); }); @@ -177,7 +177,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(0)), + flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(0)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); From 540561c1179deef282088a204016dffdbbbb1ba9 Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Fri, 8 Dec 2023 22:36:57 +0900 Subject: [PATCH 11/13] feat(scheduler): fix build --- packages/@aws-cdk/aws-scheduler-alpha/README.md | 6 +++--- packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts | 8 ++++---- .../@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts | 2 +- .../@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index 4b0cfc6917f7f..feb6785372e01 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -227,10 +227,10 @@ const schedule = new Schedule(this, 'Schedule', { > Visit [Data protection in Amazon EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/data-protection.html) for more details. -## Configuring flexible time window +## Configuring flexible time windows You can configure flexible time windows by specifying the `flexibleTimeWindow` property. -By default, the mode of `flexibleTimeWindow` is set to `OFF` and this feature is disabled. +Flexible time windows is disabled by default. ```ts declare const target: targets.LambdaInvoke; @@ -238,7 +238,7 @@ declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { schedule: ScheduleExpression.rate(Duration.hours(12)), target, - flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.hours(10)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.hours(10)), }); ``` diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index d514038a81564..a07ec73ab710a 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -66,14 +66,14 @@ export class FlexibleTimeWindowMode { /** * FlexibleTimeWindow is disabled. */ - public static Off(): FlexibleTimeWindowMode { + public static off(): FlexibleTimeWindowMode { return new FlexibleTimeWindowMode('OFF'); } /** * FlexibleTimeWindow is enabled. */ - public static Flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { + public static flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); } @@ -162,7 +162,7 @@ export interface ScheduleProps { * * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html * - * @default FlexibleTimeWindowMode.Off() + * @default FlexibleTimeWindowMode.off() */ readonly flexibleTimeWindow?: FlexibleTimeWindowMode; } @@ -305,7 +305,7 @@ export class Schedule extends Resource implements ISchedule { this.retryPolicy = targetConfig.retryPolicy; - const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.Off(); + const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.off(); const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 6d3ce3cc1df04..6dc0a69001e86 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -93,7 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { schedule: expression, target: target, - flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.Flexible(cdk.Duration.minutes(10)), + flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.flexible(cdk.Duration.minutes(10)), }); new IntegTest(app, 'integtest-schedule', { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index eb281917365ad..f286f80875030 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -150,7 +150,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1440)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1440)), }); // THEN @@ -167,7 +167,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1441)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1441)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); }); @@ -177,7 +177,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(0)), + flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(0)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); From f509ef66d0b7308752177905c541c1a190ada9dd Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Wed, 13 Dec 2023 21:29:35 +0900 Subject: [PATCH 12/13] feat(scheduler): fix for the review --- .../@aws-cdk/aws-scheduler-alpha/README.md | 4 +-- .../aws-scheduler-alpha/lib/schedule.ts | 36 +++++++++---------- .../rosetta/default.ts-fixture | 2 +- .../test/integ.schedule.ts | 2 +- .../aws-scheduler-alpha/test/schedule.test.ts | 8 ++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/README.md b/packages/@aws-cdk/aws-scheduler-alpha/README.md index feb6785372e01..41d5c39839625 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/README.md +++ b/packages/@aws-cdk/aws-scheduler-alpha/README.md @@ -229,7 +229,7 @@ const schedule = new Schedule(this, 'Schedule', { ## Configuring flexible time windows -You can configure flexible time windows by specifying the `flexibleTimeWindow` property. +You can configure flexible time windows by specifying the `timeWindow` property. Flexible time windows is disabled by default. ```ts @@ -238,7 +238,7 @@ declare const target: targets.LambdaInvoke; const schedule = new Schedule(this, 'Schedule', { schedule: ScheduleExpression.rate(Duration.hours(12)), target, - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.hours(10)), + timeWindow: TimeWindow.flexible(Duration.hours(10)), }); ``` diff --git a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts index d1afa2b5df972..395c4ca766f42 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts @@ -62,41 +62,41 @@ export interface ScheduleTargetProps { /** * A time window during which EventBridge Scheduler invokes the schedule. */ -export class FlexibleTimeWindowMode { +export class TimeWindow { /** - * FlexibleTimeWindow is disabled. + * TimeWindow is disabled. */ - public static off(): FlexibleTimeWindowMode { - return new FlexibleTimeWindowMode('OFF'); + public static off(): TimeWindow { + return new TimeWindow('OFF'); } /** - * FlexibleTimeWindow is enabled. + * TimeWindow is enabled. */ - public static flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode { - if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) { - throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`); + public static flexible(maxWindow: Duration): TimeWindow { + if (maxWindow.toMinutes() < 1 || maxWindow.toMinutes() > 1440) { + throw new Error(`The provided duration must be between 1 minute and 1440 minutes, got ${maxWindow.toMinutes()}`); } - return new FlexibleTimeWindowMode('FLEXIBLE', maximumWindowInMinutes); + return new TimeWindow('FLEXIBLE', maxWindow); } /** * Determines whether the schedule is invoked within a flexible time window. */ - public readonly mode: string; + public readonly mode: 'OFF' | 'FLEXIBLE'; /** * The maximum time window during which the schedule can be invoked. * * Must be between 1 to 1440 minutes. * - * @default - Required if mode is FLEXIBLE. + * @default - no value */ - public readonly maximumWindowInMinutes?: Duration; + public readonly maxWindow?: Duration; - private constructor(mode: string, maximumWindowInMinutes?: Duration) { + private constructor(mode: 'OFF' | 'FLEXIBLE', maxWindow?: Duration) { this.mode = mode; - this.maximumWindowInMinutes = maximumWindowInMinutes; + this.maxWindow = maxWindow; } } @@ -162,9 +162,9 @@ export interface ScheduleProps { * * @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html * - * @default FlexibleTimeWindowMode.off() + * @default TimeWindow.off() */ - readonly flexibleTimeWindow?: FlexibleTimeWindowMode; + readonly timeWindow?: TimeWindow; } /** @@ -305,13 +305,13 @@ export class Schedule extends Resource implements ISchedule { this.retryPolicy = targetConfig.retryPolicy; - const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.off(); + const flexibleTimeWindow = props.timeWindow ?? TimeWindow.off(); const resource = new CfnSchedule(this, 'Resource', { name: this.physicalName, flexibleTimeWindow: { mode: flexibleTimeWindow.mode, - maximumWindowInMinutes: flexibleTimeWindow.maximumWindowInMinutes?.toMinutes(), + maximumWindowInMinutes: flexibleTimeWindow.maxWindow?.toMinutes(), }, scheduleExpression: props.schedule.expressionString, scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName, diff --git a/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture index c3b6690b5e25b..4c66c83a7dd44 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-scheduler-alpha/rosetta/default.ts-fixture @@ -8,7 +8,7 @@ import * as sqs from 'aws-cdk-lib/aws-sqs'; import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; import * as targets from '@aws-cdk/aws-scheduler-targets-alpha'; import { App, Stack, TimeZone, Duration } from 'aws-cdk-lib'; -import { ScheduleExpression, ScheduleTargetInput, ContextAttribute, Group, Schedule, FlexibleTimeWindowMode } from '@aws-cdk/aws-scheduler-alpha'; +import { ScheduleExpression, ScheduleTargetInput, ContextAttribute, Group, Schedule, TimeWindow } from '@aws-cdk/aws-scheduler-alpha'; class Fixture extends cdk.Stack { constructor(scope: Construct, id: string) { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts index 6dc0a69001e86..61f36442b59f7 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts @@ -93,7 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', { new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', { schedule: expression, target: target, - flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.flexible(cdk.Duration.minutes(10)), + timeWindow: scheduler.TimeWindow.flexible(cdk.Duration.minutes(10)), }); new IntegTest(app, 'integtest-schedule', { diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index f286f80875030..a1517cf761c22 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -4,7 +4,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { IScheduleTarget, Schedule, ScheduleTargetConfig, FlexibleTimeWindowMode } from '../lib'; +import { IScheduleTarget, Schedule, ScheduleTargetConfig, TimeWindow } from '../lib'; import { ScheduleExpression } from '../lib/schedule-expression'; class SomeLambdaTarget implements IScheduleTarget { @@ -150,7 +150,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1440)), + timeWindow: TimeWindow.flexible(Duration.minutes(1440)), }); // THEN @@ -167,7 +167,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1441)), + timeWindow: TimeWindow.flexible(Duration.minutes(1441)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); }); @@ -177,7 +177,7 @@ describe('Schedule', () => { new Schedule(stack, 'TestSchedule', { schedule: expr, target: new SomeLambdaTarget(func, role), - flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(0)), + timeWindow: TimeWindow.flexible(Duration.minutes(0)), }); }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); }); From 461f5bae0331cb690f1eacc39c0d1a20cca67f0d Mon Sep 17 00:00:00 2001 From: sakurai-ryo Date: Wed, 13 Dec 2023 22:17:41 +0900 Subject: [PATCH 13/13] feat(scheduler): fix tests --- packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts index a1517cf761c22..e0206a65ac6fe 100644 --- a/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts +++ b/packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts @@ -169,7 +169,7 @@ describe('Schedule', () => { target: new SomeLambdaTarget(func, role), timeWindow: TimeWindow.flexible(Duration.minutes(1441)), }); - }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441'); + }).toThrow('The provided duration must be between 1 minute and 1440 minutes, got 1441'); }); test('throw error when maximumWindowInMinutes is less than 1', () => { @@ -179,7 +179,7 @@ describe('Schedule', () => { target: new SomeLambdaTarget(func, role), timeWindow: TimeWindow.flexible(Duration.minutes(0)), }); - }).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0'); + }).toThrow('The provided duration must be between 1 minute and 1440 minutes, got 0'); }); }); }); \ No newline at end of file