Skip to content

Commit

Permalink
feat(core): Schedule class (#27105)
Browse files Browse the repository at this point in the history
My latest attempt at schedule unification across modules. 

The following modules use a version of schedule, which this PR aims to unify:

- aws-scheduler-alpha
- aws-events
- aws-application-autoscaling
- aws-autoscaling
- aws-synthetics-alpha
- aws-backup

The idea is to have a single source of truth, `core.Schedule` that is exposed and meant to be extended by modules that use a schedule. This is to avoid breaking changes -- every module that currently exports a schedule class continues to do so. Each module can customize their schedule class to its liking, for example, whether or not to support `schedule.at` or `cronOptions.timeZone`.

This PR will fix inconsistencies like:

  - `backup.scheduleExpression` depending on `events.Schedule`, which is semi-deprecated by the Events team (they want people to use the Schedule class in `aws-scheduler-alpha`). 
  - `aws-scheduler-alpha` depending on `events.Schedule` as well.
  - `backup.scheduleExpression` allowing `schedule.rate(duration)` to be specified (synth-time error) when we know that backup schedules only can be cron expressions.
  - having to implement the new `timeZone` property in all instances of schedules
  - avoids us from having to perform maintenance in multiple places like #19197
  - `timeZone` property existing directly on a construct when it only pertains to `cron` expressions. This is an anomaly because we typically do not want construct-level properties to only be impactful depending on other properties. [See superseded PRs]


Challenges:

  - subtle differences in expressions that are accepted. This is solved by `core.Schedule` only exposing `protected` APIs, which are then picked by the consuming modules to be exposed as `public`.
  - subtle difference in `cron` expressions accepted. I do some magic in `aws-autoscaling` to get the cron expression returned there to be as expected.

Supersedes #27052 and #27012

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Sep 20, 2023
1 parent 2855da6 commit a8f0a71
Show file tree
Hide file tree
Showing 47 changed files with 622 additions and 558 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"version": "34.0.0",
"files": {
"0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5": {
"7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976": {
"source": {
"path": "cdk-backup.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5.json",
"objectKey": "7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
},
"RuleName": "Daily",
"ScheduleExpression": "cron(0 5 * * ? *)",
"ScheduleExpressionTimezone": "Etc/UTC",
"TargetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand All @@ -96,6 +97,7 @@
},
"RuleName": "Weekly",
"ScheduleExpression": "cron(0 5 ? * SAT *)",
"ScheduleExpressionTimezone": "Etc/UTC",
"TargetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand All @@ -110,6 +112,7 @@
},
"RuleName": "Monthly5Year",
"ScheduleExpression": "cron(0 5 1 * ? *)",
"ScheduleExpressionTimezone": "Etc/UTC",
"TargetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"32.0.0"}
{"version":"34.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "33.0.0",
"version": "34.0.0",
"testCases": {
"integ.backup": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "33.0.0",
"version": "34.0.0",
"artifacts": {
"cdk-backup.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -14,10 +14,11 @@
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "cdk-backup.template.json",
"terminationProtection": false,
"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}/0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_dynamodb.CfnTable",
"version": "0.0.0"
}
},
"ScalingRole": {
"id": "ScalingRole",
"path": "cdk-backup/Table/ScalingRole",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_dynamodb.Table",
"version": "0.0.0"
}
},
"FileSystem": {
Expand All @@ -63,8 +63,8 @@
"aws:cdk:cloudformation:props": {}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_efs.CfnFileSystem",
"version": "0.0.0"
}
},
"Vault": {
Expand All @@ -84,14 +84,14 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
"version": "0.0.0"
}
},
"SecondaryVault": {
Expand All @@ -111,22 +111,22 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
"version": "0.0.0"
}
},
"Env": {
"id": "Env",
"path": "cdk-backup/Env",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.CfnParameter",
"version": "0.0.0"
}
},
"ThirdVault": {
Expand Down Expand Up @@ -156,14 +156,14 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
"version": "0.0.0"
}
},
"Plan": {
Expand All @@ -185,6 +185,7 @@
},
"ruleName": "Daily",
"scheduleExpression": "cron(0 5 * * ? *)",
"scheduleExpressionTimezone": "Etc/UTC",
"targetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand All @@ -198,6 +199,7 @@
},
"ruleName": "Weekly",
"scheduleExpression": "cron(0 5 ? * SAT *)",
"scheduleExpressionTimezone": "Etc/UTC",
"targetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand All @@ -212,6 +214,7 @@
},
"ruleName": "Monthly5Year",
"scheduleExpression": "cron(0 5 1 * ? *)",
"scheduleExpressionTimezone": "Etc/UTC",
"targetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
Expand Down Expand Up @@ -250,8 +253,8 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupPlan",
"version": "0.0.0"
}
},
"Selection": {
Expand All @@ -266,8 +269,8 @@
"id": "ImportRole",
"path": "cdk-backup/Plan/Selection/Role/ImportRole",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
},
"Resource": {
Expand Down Expand Up @@ -305,14 +308,14 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_iam.Role",
"version": "0.0.0"
}
},
"Resource": {
Expand Down Expand Up @@ -394,56 +397,56 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupSelection",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.BackupSelection",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.BackupPlan",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "cdk-backup/BootstrapVersion",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "cdk-backup/CheckBootstrapVersion",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.Stack",
"version": "0.0.0"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"version": "10.2.70"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.App",
"version": "0.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "20.0.0",
"version": "34.0.0",
"files": {
"619c64c0f19a7d78d759641bfba47f06ebbd7ffb42aae71ec695a6777a534d01": {
"865151155140d0ba599d3522f659db77ada497ea1a763cf11c3fb58d017a3082": {
"source": {
"path": "aws-cdk-dynamodb.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "619c64c0f19a7d78d759641bfba47f06ebbd7ffb42aae71ec695a6777a534d01.json",
"objectKey": "865151155140d0ba599d3522f659db77ada497ea1a763cf11c3fb58d017a3082.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"TableCD117FA1": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"KeySchema": [
"AttributeDefinitions": [
{
"AttributeName": "hashKey",
"KeyType": "HASH"
"AttributeType": "S"
}
],
"AttributeDefinitions": [
"KeySchema": [
{
"AttributeName": "hashKey",
"AttributeType": "S"
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
Expand Down Expand Up @@ -56,23 +56,25 @@
]
},
"ScalableDimension": "dynamodb:table:ReadCapacityUnits",
"ServiceNamespace": "dynamodb",
"ScheduledActions": [
{
"ScalableTargetAction": {
"MinCapacity": 20
},
"Schedule": "cron(0 8 * * ? *)",
"ScheduledActionName": "ScaleUpInTheMorning"
"ScheduledActionName": "ScaleUpInTheMorning",
"Timezone": "Etc/UTC"
},
{
"ScalableTargetAction": {
"MaxCapacity": 20
},
"Schedule": "cron(0 20 * * ? *)",
"ScheduledActionName": "ScaleDownAtNight"
"ScheduledActionName": "ScaleDownAtNight",
"Timezone": "Etc/UTC"
}
]
],
"ServiceNamespace": "dynamodb"
}
},
"TableReadScalingTargetTracking67DF0596": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"20.0.0"}
{"version":"34.0.0"}
Loading

0 comments on commit a8f0a71

Please sign in to comment.