Skip to content

Commit a8f0a71

Browse files
authored
feat(core): Schedule class (#27105)
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*
1 parent 2855da6 commit a8f0a71

File tree

47 files changed

+622
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+622
-558
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/cdk-backup.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "32.0.0",
2+
"version": "34.0.0",
33
"files": {
4-
"0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5": {
4+
"7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976": {
55
"source": {
66
"path": "cdk-backup.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5.json",
12+
"objectKey": "7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/cdk-backup.template.json

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
},
8484
"RuleName": "Daily",
8585
"ScheduleExpression": "cron(0 5 * * ? *)",
86+
"ScheduleExpressionTimezone": "Etc/UTC",
8687
"TargetBackupVault": {
8788
"Fn::GetAtt": [
8889
"Vault23237E5B",
@@ -96,6 +97,7 @@
9697
},
9798
"RuleName": "Weekly",
9899
"ScheduleExpression": "cron(0 5 ? * SAT *)",
100+
"ScheduleExpressionTimezone": "Etc/UTC",
99101
"TargetBackupVault": {
100102
"Fn::GetAtt": [
101103
"Vault23237E5B",
@@ -110,6 +112,7 @@
110112
},
111113
"RuleName": "Monthly5Year",
112114
"ScheduleExpression": "cron(0 5 1 * ? *)",
115+
"ScheduleExpressionTimezone": "Etc/UTC",
113116
"TargetBackupVault": {
114117
"Fn::GetAtt": [
115118
"Vault23237E5B",
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"32.0.0"}
1+
{"version":"34.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "33.0.0",
2+
"version": "34.0.0",
33
"testCases": {
44
"integ.backup": {
55
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/manifest.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "33.0.0",
2+
"version": "34.0.0",
33
"artifacts": {
44
"cdk-backup.assets": {
55
"type": "cdk:asset-manifest",
@@ -14,10 +14,11 @@
1414
"environment": "aws://unknown-account/unknown-region",
1515
"properties": {
1616
"templateFile": "cdk-backup.template.json",
17+
"terminationProtection": false,
1718
"validateOnSynth": false,
1819
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1920
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5.json",
21+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7617f116cb014747232d2ebeb42fb3e22242c4b0987526daf7a033aba236d976.json",
2122
"requiresBootstrapStackVersion": 6,
2223
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2324
"additionalDependencies": [

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/tree.json

+48-45
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@
3737
}
3838
},
3939
"constructInfo": {
40-
"fqn": "constructs.Construct",
41-
"version": "10.2.69"
40+
"fqn": "aws-cdk-lib.aws_dynamodb.CfnTable",
41+
"version": "0.0.0"
4242
}
4343
},
4444
"ScalingRole": {
4545
"id": "ScalingRole",
4646
"path": "cdk-backup/Table/ScalingRole",
4747
"constructInfo": {
48-
"fqn": "constructs.Construct",
49-
"version": "10.2.69"
48+
"fqn": "aws-cdk-lib.Resource",
49+
"version": "0.0.0"
5050
}
5151
}
5252
},
5353
"constructInfo": {
54-
"fqn": "constructs.Construct",
55-
"version": "10.2.69"
54+
"fqn": "aws-cdk-lib.aws_dynamodb.Table",
55+
"version": "0.0.0"
5656
}
5757
},
5858
"FileSystem": {
@@ -63,8 +63,8 @@
6363
"aws:cdk:cloudformation:props": {}
6464
},
6565
"constructInfo": {
66-
"fqn": "constructs.Construct",
67-
"version": "10.2.69"
66+
"fqn": "aws-cdk-lib.aws_efs.CfnFileSystem",
67+
"version": "0.0.0"
6868
}
6969
},
7070
"Vault": {
@@ -84,14 +84,14 @@
8484
}
8585
},
8686
"constructInfo": {
87-
"fqn": "constructs.Construct",
88-
"version": "10.2.69"
87+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
88+
"version": "0.0.0"
8989
}
9090
}
9191
},
9292
"constructInfo": {
93-
"fqn": "constructs.Construct",
94-
"version": "10.2.69"
93+
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
94+
"version": "0.0.0"
9595
}
9696
},
9797
"SecondaryVault": {
@@ -111,22 +111,22 @@
111111
}
112112
},
113113
"constructInfo": {
114-
"fqn": "constructs.Construct",
115-
"version": "10.2.69"
114+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
115+
"version": "0.0.0"
116116
}
117117
}
118118
},
119119
"constructInfo": {
120-
"fqn": "constructs.Construct",
121-
"version": "10.2.69"
120+
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
121+
"version": "0.0.0"
122122
}
123123
},
124124
"Env": {
125125
"id": "Env",
126126
"path": "cdk-backup/Env",
127127
"constructInfo": {
128-
"fqn": "constructs.Construct",
129-
"version": "10.2.69"
128+
"fqn": "aws-cdk-lib.CfnParameter",
129+
"version": "0.0.0"
130130
}
131131
},
132132
"ThirdVault": {
@@ -156,14 +156,14 @@
156156
}
157157
},
158158
"constructInfo": {
159-
"fqn": "constructs.Construct",
160-
"version": "10.2.69"
159+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
160+
"version": "0.0.0"
161161
}
162162
}
163163
},
164164
"constructInfo": {
165-
"fqn": "constructs.Construct",
166-
"version": "10.2.69"
165+
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
166+
"version": "0.0.0"
167167
}
168168
},
169169
"Plan": {
@@ -185,6 +185,7 @@
185185
},
186186
"ruleName": "Daily",
187187
"scheduleExpression": "cron(0 5 * * ? *)",
188+
"scheduleExpressionTimezone": "Etc/UTC",
188189
"targetBackupVault": {
189190
"Fn::GetAtt": [
190191
"Vault23237E5B",
@@ -198,6 +199,7 @@
198199
},
199200
"ruleName": "Weekly",
200201
"scheduleExpression": "cron(0 5 ? * SAT *)",
202+
"scheduleExpressionTimezone": "Etc/UTC",
201203
"targetBackupVault": {
202204
"Fn::GetAtt": [
203205
"Vault23237E5B",
@@ -212,6 +214,7 @@
212214
},
213215
"ruleName": "Monthly5Year",
214216
"scheduleExpression": "cron(0 5 1 * ? *)",
217+
"scheduleExpressionTimezone": "Etc/UTC",
215218
"targetBackupVault": {
216219
"Fn::GetAtt": [
217220
"Vault23237E5B",
@@ -250,8 +253,8 @@
250253
}
251254
},
252255
"constructInfo": {
253-
"fqn": "constructs.Construct",
254-
"version": "10.2.69"
256+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupPlan",
257+
"version": "0.0.0"
255258
}
256259
},
257260
"Selection": {
@@ -266,8 +269,8 @@
266269
"id": "ImportRole",
267270
"path": "cdk-backup/Plan/Selection/Role/ImportRole",
268271
"constructInfo": {
269-
"fqn": "constructs.Construct",
270-
"version": "10.2.69"
272+
"fqn": "aws-cdk-lib.Resource",
273+
"version": "0.0.0"
271274
}
272275
},
273276
"Resource": {
@@ -305,14 +308,14 @@
305308
}
306309
},
307310
"constructInfo": {
308-
"fqn": "constructs.Construct",
309-
"version": "10.2.69"
311+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
312+
"version": "0.0.0"
310313
}
311314
}
312315
},
313316
"constructInfo": {
314-
"fqn": "constructs.Construct",
315-
"version": "10.2.69"
317+
"fqn": "aws-cdk-lib.aws_iam.Role",
318+
"version": "0.0.0"
316319
}
317320
},
318321
"Resource": {
@@ -394,56 +397,56 @@
394397
}
395398
},
396399
"constructInfo": {
397-
"fqn": "constructs.Construct",
398-
"version": "10.2.69"
400+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupSelection",
401+
"version": "0.0.0"
399402
}
400403
}
401404
},
402405
"constructInfo": {
403-
"fqn": "constructs.Construct",
404-
"version": "10.2.69"
406+
"fqn": "aws-cdk-lib.aws_backup.BackupSelection",
407+
"version": "0.0.0"
405408
}
406409
}
407410
},
408411
"constructInfo": {
409-
"fqn": "constructs.Construct",
410-
"version": "10.2.69"
412+
"fqn": "aws-cdk-lib.aws_backup.BackupPlan",
413+
"version": "0.0.0"
411414
}
412415
},
413416
"BootstrapVersion": {
414417
"id": "BootstrapVersion",
415418
"path": "cdk-backup/BootstrapVersion",
416419
"constructInfo": {
417-
"fqn": "constructs.Construct",
418-
"version": "10.2.69"
420+
"fqn": "aws-cdk-lib.CfnParameter",
421+
"version": "0.0.0"
419422
}
420423
},
421424
"CheckBootstrapVersion": {
422425
"id": "CheckBootstrapVersion",
423426
"path": "cdk-backup/CheckBootstrapVersion",
424427
"constructInfo": {
425-
"fqn": "constructs.Construct",
426-
"version": "10.2.69"
428+
"fqn": "aws-cdk-lib.CfnRule",
429+
"version": "0.0.0"
427430
}
428431
}
429432
},
430433
"constructInfo": {
431-
"fqn": "constructs.Construct",
432-
"version": "10.2.69"
434+
"fqn": "aws-cdk-lib.Stack",
435+
"version": "0.0.0"
433436
}
434437
},
435438
"Tree": {
436439
"id": "Tree",
437440
"path": "Tree",
438441
"constructInfo": {
439442
"fqn": "constructs.Construct",
440-
"version": "10.2.69"
443+
"version": "10.2.70"
441444
}
442445
}
443446
},
444447
"constructInfo": {
445-
"fqn": "constructs.Construct",
446-
"version": "10.2.69"
448+
"fqn": "aws-cdk-lib.App",
449+
"version": "0.0.0"
447450
}
448451
}
449452
}

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.autoscaling.lit.js.snapshot/aws-cdk-dynamodb.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "34.0.0",
33
"files": {
4-
"619c64c0f19a7d78d759641bfba47f06ebbd7ffb42aae71ec695a6777a534d01": {
4+
"865151155140d0ba599d3522f659db77ada497ea1a763cf11c3fb58d017a3082": {
55
"source": {
66
"path": "aws-cdk-dynamodb.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "619c64c0f19a7d78d759641bfba47f06ebbd7ffb42aae71ec695a6777a534d01.json",
12+
"objectKey": "865151155140d0ba599d3522f659db77ada497ea1a763cf11c3fb58d017a3082.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.autoscaling.lit.js.snapshot/aws-cdk-dynamodb.template.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"TableCD117FA1": {
44
"Type": "AWS::DynamoDB::Table",
55
"Properties": {
6-
"KeySchema": [
6+
"AttributeDefinitions": [
77
{
88
"AttributeName": "hashKey",
9-
"KeyType": "HASH"
9+
"AttributeType": "S"
1010
}
1111
],
12-
"AttributeDefinitions": [
12+
"KeySchema": [
1313
{
1414
"AttributeName": "hashKey",
15-
"AttributeType": "S"
15+
"KeyType": "HASH"
1616
}
1717
],
1818
"ProvisionedThroughput": {
@@ -56,23 +56,25 @@
5656
]
5757
},
5858
"ScalableDimension": "dynamodb:table:ReadCapacityUnits",
59-
"ServiceNamespace": "dynamodb",
6059
"ScheduledActions": [
6160
{
6261
"ScalableTargetAction": {
6362
"MinCapacity": 20
6463
},
6564
"Schedule": "cron(0 8 * * ? *)",
66-
"ScheduledActionName": "ScaleUpInTheMorning"
65+
"ScheduledActionName": "ScaleUpInTheMorning",
66+
"Timezone": "Etc/UTC"
6767
},
6868
{
6969
"ScalableTargetAction": {
7070
"MaxCapacity": 20
7171
},
7272
"Schedule": "cron(0 20 * * ? *)",
73-
"ScheduledActionName": "ScaleDownAtNight"
73+
"ScheduledActionName": "ScaleDownAtNight",
74+
"Timezone": "Etc/UTC"
7475
}
75-
]
76+
],
77+
"ServiceNamespace": "dynamodb"
7678
}
7779
},
7880
"TableReadScalingTargetTracking67DF0596": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"34.0.0"}

0 commit comments

Comments
 (0)