Skip to content

LifecyclePolicy

Source: src/AWS/DLM/LifecyclePolicy.ts

An Amazon Data Lifecycle Manager (DLM) lifecycle policy that automates the creation, retention, and deletion of EBS snapshots or EBS-backed AMIs.

LifecyclePolicy owns a custom EBS_SNAPSHOT_MANAGEMENT or IMAGE_MANAGEMENT policy. Volumes/instances are targeted by tags, and an execution role is created automatically unless an explicit executionRoleArn is given.

Daily EBS snapshots retained for a week

import * as DLM from "alchemy/AWS/DLM";
const policy = yield* DLM.LifecyclePolicy("DailySnapshots", {
policyDetails: {
resourceTypes: ["VOLUME"],
targetTags: { Backup: "daily" },
schedules: [
{
name: "Daily",
createRule: { interval: 24, intervalUnit: "HOURS", times: ["03:00"] },
retainRule: { count: 7 },
},
],
},
});

Cron-scheduled snapshots

const policy = yield* DLM.LifecyclePolicy("WeeklySnapshots", {
description: "Weekly volume snapshots",
policyDetails: {
resourceTypes: ["VOLUME"],
targetTags: { Backup: "weekly" },
schedules: [
{
name: "Weekly",
copyTags: true,
createRule: { cronExpression: "cron(0 4 ? * SUN *)" },
retainRule: { interval: 1, intervalUnit: "MONTHS" },
},
],
},
});
const amis = yield* DLM.LifecyclePolicy("NightlyAmis", {
policyDetails: {
policyType: "IMAGE_MANAGEMENT",
resourceTypes: ["INSTANCE"],
targetTags: { Backup: "ami" },
parameters: { noReboot: true },
schedules: [
{
name: "Nightly",
createRule: { interval: 24, intervalUnit: "HOURS", times: ["05:00"] },
retainRule: { count: 3 },
},
],
},
});
const role = yield* IAM.Role("DlmRole", {
assumeRolePolicyDocument: {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: { Service: "dlm.amazonaws.com" },
Action: "sts:AssumeRole",
},
],
},
managedPolicyArns: [
"arn:aws:iam::aws:policy/service-role/AWSDataLifecycleManagerServiceRole",
],
});
const policy = yield* DLM.LifecyclePolicy("Snapshots", {
executionRoleArn: role.roleArn,
state: "DISABLED",
policyDetails: {
resourceTypes: ["VOLUME"],
targetTags: { Backup: "true" },
schedules: [
{
name: "Daily",
createRule: { interval: 24, intervalUnit: "HOURS" },
retainRule: { count: 2 },
},
],
},
});