Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backup): schedule expression timezone for backup plans #27012

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"version": "34.0.0",
"files": {
"0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5": {
"92fad8a62da258c4bcae7ecf5ebdde433e9614aec519088b7a03a22067623d5e": {
"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": "92fad8a62da258c4bcae7ecf5ebdde433e9614aec519088b7a03a22067623d5e.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 @@ -142,6 +142,17 @@
"BackupVaultName"
]
}
},
{
"RuleName": "PlanRule4",
"ScheduleExpression": "cron(0 4 15 * ? *)",
"ScheduleExpressionTimezone": "Europe/Brussels",
"TargetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
"BackupVaultName"
]
}
}
]
}
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 @@ -17,7 +17,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}/0c52c355c71ac95690274d7987110017ff9cd1a1bc79fa4206fda2f55d6b62d5.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/92fad8a62da258c4bcae7ecf5ebdde433e9614aec519088b7a03a22067623d5e.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 Down Expand Up @@ -244,14 +244,25 @@
"recoveryPointTags": {
"stage": "prod"
}
},
{
"ruleName": "PlanRule4",
"scheduleExpression": "cron(0 4 15 * ? *)",
"scheduleExpressionTimezone": "Europe/Brussels",
"targetBackupVault": {
"Fn::GetAtt": [
"Vault23237E5B",
"BackupVaultName"
]
}
}
]
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.69"
"fqn": "aws-cdk-lib.aws_backup.CfnBackupPlan",
"version": "0.0.0"
}
},
"Selection": {
Expand All @@ -266,8 +277,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 +316,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 +405,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,5 +1,6 @@
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as efs from 'aws-cdk-lib/aws-efs';
import * as events from 'aws-cdk-lib/aws-events';
import { App, Duration, RemovalPolicy, Stack, StackProps, CfnParameter } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as backup from 'aws-cdk-lib/aws-backup';
Expand Down Expand Up @@ -61,6 +62,15 @@ class TestStack extends Stack {
stage: 'prod',
},
}));

plan.addRule(new backup.BackupPlanRule({
scheduleExpression: events.Schedule.cron({
day: '15',
hour: '4',
minute: '0',
}),
scheduleExpressionTimezone: 'Europe/Brussels',
}));
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ plan.addRule(new backup.BackupPlanRule({
hour: '3',
minute: '30',
}),
scheduleExpressionTimezone: 'Europe/Brussels', // Optional, defaults to UTC
moveToColdStorageAfter: Duration.days(30),
}));
```
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-backup/lib/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class BackupPlan extends Resource implements IBackupPlan {
},
ruleName: rule.props.ruleName ?? `${this.node.id}Rule${this.rules.length}`,
scheduleExpression: rule.props.scheduleExpression?.expressionString,
scheduleExpressionTimezone: rule.props.scheduleExpressionTimezone,
startWindowMinutes: rule.props.startWindow?.toMinutes(),
enableContinuousBackup: rule.props.enableContinuousBackup,
targetBackupVault: vault.backupVaultName,
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-backup/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ export interface BackupPlanRuleProps {
*/
readonly scheduleExpression?: events.Schedule;

/**
* The name of the time zone for the schedule expression, following the IANA time zone standard.
*
* @example America/Los_Angeles
*
* @see https://www.iana.org/time-zones
*
* @default - UTC
*/
readonly scheduleExpressionTimezone?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we export a TimeZone prop out of core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed that one


/**
* The duration after a backup is scheduled before a job is canceled if it doesn't start successfully.
*
Expand Down Expand Up @@ -213,6 +224,10 @@ export class BackupPlanRule {
throw new Error('`scheduleExpression` must be of type `cron`');
}

if (props.scheduleExpressionTimezone && !props.scheduleExpression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some scheduleExpressions that don't make sense with a timezone, and this check ignores that.

throw new Error('Cannot specify `scheduleExpressionTimezone` for a rule without a `scheduleExpression`');
}

const deleteAfter = (props.enableContinuousBackup && !props.deleteAfter) ? Duration.days(35) : props.deleteAfter;

if (props.enableContinuousBackup && props.moveToColdStorageAfter) {
Expand Down
Loading
Loading