Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sakurai-ryo/aws-cdk into …
Browse files Browse the repository at this point in the history
…feat-scheduler-flex-window
  • Loading branch information
sakurai-ryo committed Dec 14, 2023
2 parents 461f5ba + 93681e0 commit e990c2a
Show file tree
Hide file tree
Showing 31 changed files with 615 additions and 436 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
"@types/prettier": "2.6.0",
"@yarnpkg/lockfile": "^1.1.0",
"aws-sdk-js-codemod": "^0.28.2",
"cdk-generate-synthetic-examples": "^0.1.298",
"cdk-generate-synthetic-examples": "^0.1.299",
"conventional-changelog-cli": "^2.2.2",
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.11",
"jest-junit": "^13.2.0",
"jsii-diff": "1.92.0",
"jsii-pacmak": "1.92.0",
"jsii-reflect": "1.92.0",
"jsii-rosetta": "~5.2.5",
"jsii-diff": "1.93.0",
"jsii-pacmak": "1.93.0",
"jsii-reflect": "1.93.0",
"jsii-rosetta": "~5.2.6",
"lerna": "^7.4.2",
"nx": "^16.10.0",
"patch-package": "^6.5.1",
"semver": "^7.5.4",
"standard-version": "^9.5.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "~5.1.6"
},
"resolutions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@octokit/rest": "^18.12.0",
"aws-sdk": "^2.1513.0",
"aws-sdk": "^2.1517.0",
"axios": "^1.6.2",
"fs-extra": "^9.1.0",
"glob": "^7.2.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk-testing/framework-integ/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"@aws-cdk/integ-tests-alpha": "0.0.0",
"@aws-cdk/lambda-layer-kubectl-v24": "^2.0.242",
"aws-cdk-lib": "0.0.0",
"aws-sdk": "^2.1513.0",
"aws-sdk": "^2.1517.0",
"aws-sdk-mock": "5.6.0",
"cdk8s": "2.68.15",
"cdk8s-plus-27": "2.7.69",
"cdk8s": "2.68.18",
"cdk8s-plus-27": "2.7.70",
"constructs": "^10.0.0"
},
"repository": {
Expand Down
14 changes: 12 additions & 2 deletions packages/@aws-cdk/aws-cloud9-alpha/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ export enum ImageId {
*/
AMAZON_LINUX_2 = 'amazonlinux-2-x86_64',
/**
* Create using Ubunut 18.04
* Create using Amazon Linux 2023
*/
UBUNTU_18_04 = 'ubuntu-18.04-x86_64'
AMAZON_LINUX_2023 = 'amazonlinux-2023-x86_64',
/**
* Create using Ubuntu 18.04
*
* @deprecated Since Ubuntu 18.04 has ended standard support as of May 31, 2023, we recommend you choose Ubuntu 22.04.
*/
UBUNTU_18_04 = 'ubuntu-18.04-x86_64',
/**
* Create using Ubuntu 22.04
*/
UBUNTU_22_04 = 'ubuntu-22.04-x86_64',
}
/**
* Properties for Ec2Environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ test.each([

test.each([
[ImageId.AMAZON_LINUX_2, 'amazonlinux-2-x86_64'],
[ImageId.AMAZON_LINUX_2023, 'amazonlinux-2023-x86_64'],
[ImageId.UBUNTU_18_04, 'ubuntu-18.04-x86_64'],
[ImageId.UBUNTU_22_04, 'ubuntu-22.04-x86_64'],
])('has image ID property (%s)', (imageId, expected) => {
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ new Schedule(this, 'Schedule', {
});
```

### Configuring a start and end time of the Schedule

If you choose a recurring schedule, you can set the start and end time of the Schedule by specifying the `start` and `end`.

```ts
declare const target: targets.LambdaInvoke;

new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(cdk.Duration.hours(12)),
target: target,
start: new Date('2023-01-01T00:00:00.000Z'),
end: new Date('2023-02-01T00:00:00.000Z'),
});
```

## Scheduler Targets

Expand Down
28 changes: 27 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ export interface ScheduleProps {
* @default TimeWindow.off()
*/
readonly timeWindow?: TimeWindow;

/**
* The date, in UTC, after which the schedule can begin invoking its target.
* EventBridge Scheduler ignores start for one-time schedules.
*
* @default - no value
*/
readonly start?: Date;

/**
* The date, in UTC, before which the schedule can invoke its target.
* EventBridge Scheduler ignores end for one-time schedules.
*
* @default - no value
*/
readonly end?: Date;
}

/**
Expand Down Expand Up @@ -307,6 +323,8 @@ export class Schedule extends Resource implements ISchedule {

const flexibleTimeWindow = props.timeWindow ?? TimeWindow.off();

this.validateTimeFrame(props.start, props.end);

const resource = new CfnSchedule(this, 'Resource', {
name: this.physicalName,
flexibleTimeWindow: {
Expand All @@ -332,6 +350,8 @@ export class Schedule extends Resource implements ISchedule {
sageMakerPipelineParameters: targetConfig.sageMakerPipelineParameters,
sqsParameters: targetConfig.sqsParameters,
},
startDate: props.start?.toISOString(),
endDate: props.end?.toISOString(),
});

this.scheduleName = this.getResourceNameAttribute(resource.ref);
Expand Down Expand Up @@ -362,4 +382,10 @@ export class Schedule extends Resource implements ISchedule {
const isEmptyPolicy = Object.values(policy).every(value => value === undefined);
return !isEmptyPolicy ? policy : undefined;
}
}

private validateTimeFrame(start?: Date, end?: Date) {
if (start && end && start >= end) {
throw new Error(`start must precede end, got start: ${start.toISOString()}, end: ${end.toISOString()}`);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,38 @@
}
}
}
},
"ScheduleWithTimeFrameC1C8BDCC": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"EndDate": "2025-10-01T00:00:00.000Z",
"FlexibleTimeWindow": {
"Mode": "OFF"
},
"ScheduleExpression": "rate(12 hours)",
"ScheduleExpressionTimezone": "Etc/UTC",
"StartDate": "2024-04-15T06:30:00.000Z",
"State": "ENABLED",
"Target": {
"Arn": {
"Fn::GetAtt": [
"Function76856677",
"Arn"
]
},
"Input": "\"Input Text\"",
"RetryPolicy": {
"MaximumEventAgeInSeconds": 180,
"MaximumRetryAttempts": 3
},
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn"
]
}
}
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', {
timeWindow: scheduler.TimeWindow.flexible(cdk.Duration.minutes(10)),
});

const currentYear = new Date().getFullYear();
new scheduler.Schedule(stack, 'ScheduleWithTimeFrame', {
schedule: expression,
target: target,
start: new Date(`${currentYear + 1}-04-15T06:30:00.000Z`),
end: new Date(`${currentYear + 2}-10-01T00:00:00.000Z`),
});

new IntegTest(app, 'integtest-schedule', {
testCases: [stack],
});
Expand Down
35 changes: 34 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,39 @@ describe('Schedule', () => {
});
});

describe('schedule timeFrame', () => {
test.each([
{ StartDate: '2023-04-15T06:20:00.000Z', EndDate: '2023-10-01T00:00:00.000Z' },
{ StartDate: '2023-04-15T06:25:00.000Z' },
{ EndDate: '2023-10-01T00:00:00.000Z' },
])('schedule can set start and end', (timeFrame) => {
new Schedule(stack, 'TestSchedule', {
schedule: expr,
target: new SomeLambdaTarget(func, role),
start: timeFrame.StartDate ? new Date(timeFrame.StartDate) : undefined,
end: timeFrame.EndDate ? new Date(timeFrame.EndDate) : undefined,
});

Template.fromStack(stack).hasResourceProperties('AWS::Scheduler::Schedule', {
...timeFrame,
});
});

test.each([
{ start: '2023-10-01T00:00:00.000Z', end: '2023-10-01T00:00:00.000Z' },
{ start: '2023-10-01T00:00:00.000Z', end: '2023-09-01T00:00:00.000Z' },
])('throw error when start does not come before end', ({ start, end }) => {
expect(() => {
new Schedule(stack, 'TestSchedule', {
schedule: expr,
target: new SomeLambdaTarget(func, role),
start: new Date(start),
end: new Date(end),
});
}).toThrow(`start must precede end, got start: ${start}, end: ${end}`);
});
});

describe('flexibleTimeWindow', () => {
test('flexibleTimeWindow mode is set to OFF by default', () => {
// WHEN
Expand Down Expand Up @@ -182,4 +215,4 @@ describe('Schedule', () => {
}).toThrow('The provided duration must be between 1 minute and 1440 minutes, got 0');
});
});
});
});
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cli-lib-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"aws-cdk": "0.0.0",
"constructs": "^10.0.0",
"jest": "^29.7.0",
"ts-node": "^10.9.1"
"ts-node": "^10.9.2"
},
"repository": {
"url": "https://github.com/aws/aws-cdk.git",
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
"sinon": "^9.2.4",
"nock": "^13.4.0",
"fs-extra": "^11.2.0",
"esbuild": "^0.19.8"
"esbuild": "^0.19.9"
},
"dependencies": {
"@aws-cdk/asset-node-proxy-agent-v6": "^2.0.1",
"@aws-sdk/client-lambda": "3.421.0",
"@aws-sdk/client-synthetics": "3.421.0",
"@aws-sdk/client-ecr": "3.421.0",
"@aws-sdk/client-s3": "3.421.0",
"aws-sdk": "^2.1513.0"
"aws-sdk": "^2.1517.0"
},
"repository": {
"url": "https://github.com/aws/aws-cdk.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/integ-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"constructs": "^10.0.0",
"mock-fs": "^4.14.0",
"jest": "^29.7.0",
"ts-node": "^10.9.1"
"ts-node": "^10.9.2"
},
"dependencies": {
"chokidar": "^3.5.3",
Expand Down
Loading

0 comments on commit e990c2a

Please sign in to comment.