A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
AWS Backup provides centralized backup management across AWS services.
import * as aws from "@pulumi/aws";
const plan = new aws.backup.Plan("daily-backups", {
name: "daily-backup-plan",
rule: {
ruleName: "daily-rule",
targetVaultName: vault.name,
schedule: "cron(0 2 * * ? *)", // 2 AM daily
lifecycle: {
deleteAfter: 30, // days
},
},
});import * as aws from "@pulumi/aws";
const vault = new aws.backup.Vault("backup-vault", {
name: "production-backups",
kmsKeyArn: kmsKey.arn,
tags: { Environment: "production" },
});import * as aws from "@pulumi/aws";
const selection = new aws.backup.Selection("tagged-resources", {
name: "backup-tagged-resources",
planId: plan.id,
iamRoleArn: backupRole.arn,
selectionTag: {
type: "STRINGEQUALS",
key: "Backup",
value: "true",
},
});AWS Backup manages backup plans, vaults, and resource selections for automated backup across RDS, DynamoDB, EFS, EBS, and more.
Defines backup schedule, retention, and lifecycle policies.
class Plan extends pulumi.CustomResource {
constructor(name: string, args: PlanArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
readonly id: pulumi.Output<string>;
}
interface PlanArgs {
name: pulumi.Input<string>;
rule: pulumi.Input<PlanRule | PlanRule[]>;
advancedBackupSetting?: pulumi.Input<AdvancedBackupSetting[]>;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}
interface PlanRule {
ruleName: pulumi.Input<string>;
targetVaultName: pulumi.Input<string>;
schedule?: pulumi.Input<string>; // cron expression
startWindow?: pulumi.Input<number>; // minutes
completionWindow?: pulumi.Input<number>; // minutes
lifecycle?: pulumi.Input<Lifecycle>;
recoveryPointTags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
copyAction?: pulumi.Input<CopyAction[]>;
}
interface Lifecycle {
deleteAfter?: pulumi.Input<number>; // days
moveToColdStorageAfter?: pulumi.Input<number>; // days
}Example: Comprehensive backup plan with multiple rules
const plan = new aws.backup.Plan("comprehensive-backup", {
name: "production-backup-plan",
rule: [
{
ruleName: "hourly-snapshots",
targetVaultName: vault.name,
schedule: "cron(0 * * * ? *)", // Every hour
startWindow: 60,
completionWindow: 120,
lifecycle: {
deleteAfter: 1, // Keep hourly for 1 day
},
recoveryPointTags: {
Frequency: "hourly",
},
},
{
ruleName: "daily-backups",
targetVaultName: vault.name,
schedule: "cron(0 2 * * ? *)", // 2 AM daily
lifecycle: {
deleteAfter: 30, // Keep daily for 30 days
},
recoveryPointTags: {
Frequency: "daily",
},
},
{
ruleName: "monthly-archives",
targetVaultName: vault.name,
schedule: "cron(0 3 1 * ? *)", // 3 AM on 1st of month
lifecycle: {
moveToColdStorageAfter: 30,
deleteAfter: 365, // Keep for 1 year
},
recoveryPointTags: {
Frequency: "monthly",
},
},
],
tags: {
Environment: "production",
ManagedBy: "aws-backup",
},
});Example: Cross-region backup replication
const drVault = new aws.backup.Vault("dr-vault", {
name: "disaster-recovery-vault",
}, { provider: drRegionProvider });
const plan = new aws.backup.Plan("replicated-backup", {
name: "cross-region-backup",
rule: {
ruleName: "daily-with-replication",
targetVaultName: primaryVault.name,
schedule: "cron(0 2 * * ? *)",
lifecycle: {
deleteAfter: 30,
},
copyAction: [{
destinationVaultArn: drVault.arn,
lifecycle: {
deleteAfter: 30,
},
}],
},
});Secure storage location for backups.
class Vault extends pulumi.CustomResource {
constructor(name: string, args?: VaultArgs, opts?: pulumi.CustomResourceOptions);
readonly arn: pulumi.Output<string>;
readonly id: pulumi.Output<string>;
}
interface VaultArgs {
name?: pulumi.Input<string>;
kmsKeyArn?: pulumi.Input<string>;
tags?: pulumi.Input<{[key: string]: pulumi.Input<string>}>;
}Example: Encrypted backup vault
const vault = new aws.backup.Vault("encrypted-vault", {
name: "production-backups",
kmsKeyArn: kmsKey.arn,
tags: {
Environment: "production",
Encrypted: "true",
},
});Example: Vault with access policy
const vault = new aws.backup.Vault("restricted-vault", {
name: "compliance-backups",
kmsKeyArn: kmsKey.arn,
});
new aws.backup.VaultPolicy("vault-policy", {
backupVaultName: vault.name,
policy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Deny",
Principal: "*",
Action: "backup:DeleteRecoveryPoint",
Resource: "*",
Condition: {
NumericLessThan: {
"backup:CopyJobId": "365"
}
}
}]
}),
});Assigns resources to backup plans.
class Selection extends pulumi.CustomResource {
constructor(name: string, args: SelectionArgs, opts?: pulumi.CustomResourceOptions);
readonly id: pulumi.Output<string>;
}
interface SelectionArgs {
name: pulumi.Input<string>;
planId: pulumi.Input<string>;
iamRoleArn: pulumi.Input<string>;
resources?: pulumi.Input<pulumi.Input<string>[]>; // ARNs
selectionTag?: pulumi.Input<SelectionTag | SelectionTag[]>;
condition?: pulumi.Input<SelectionCondition>;
}
interface SelectionTag {
type: pulumi.Input<"STRINGEQUALS">;
key: pulumi.Input<string>;
value: pulumi.Input<string>;
}Example: Select resources by tag
const selection = new aws.backup.Selection("tagged-resources", {
name: "backup-tagged-resources",
planId: plan.id,
iamRoleArn: backupRole.arn,
selectionTag: {
type: "STRINGEQUALS",
key: "Backup",
value: "true",
},
});Example: Select specific resources by ARN
const selection = new aws.backup.Selection("critical-resources", {
name: "critical-databases",
planId: plan.id,
iamRoleArn: backupRole.arn,
resources: [
db1.arn,
db2.arn,
efsFileSystem.arn,
],
});Example: Select with multiple conditions
const selection = new aws.backup.Selection("multi-condition", {
name: "production-tagged-resources",
planId: plan.id,
iamRoleArn: backupRole.arn,
selectionTag: [
{
type: "STRINGEQUALS",
key: "Environment",
value: "production",
},
{
type: "STRINGEQUALS",
key: "Backup",
value: "true",
},
],
});AWS Backup requires an IAM role with appropriate permissions:
const backupRole = new aws.iam.Role("backup-role", {
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Principal: {
Service: "backup.amazonaws.com"
},
Action: "sts:AssumeRole"
}]
}),
});
new aws.iam.RolePolicyAttachment("backup-policy", {
role: backupRole.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup",
});
new aws.iam.RolePolicyAttachment("restore-policy", {
role: backupRole.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores",
});AWS Backup supports centralized backup for:
cron(0 2 * * ? *) - Daily at 2 AM UTCcron(0 */6 * * ? *) - Every 6 hourscron(0 3 ? * MON *) - Weekly on Monday at 3 AMcron(0 4 1 * ? *) - Monthly on 1st at 4 AMcron(0 5 1 */3 ? *) - Quarterly on 1st at 5 AMFor complete Backup API with 13 resources and 5 data sources, see All Services.
Install with Tessl CLI
npx tessl i tessl/npm-pulumi--aws@7.16.0