01 Run create-tags command (OSX/Linux/UNIX) to add new tags to the AWS EBS volume targeted for snapshot automation with Amazon Data Lifecycle Manager (DLM) service. The new tag set is required by the snapshot lifecycle policy for EBS resource identification (the command does not produce an output):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws ec2 create-tags
--region us-east-1
--resources vol-0abcdabcdabcdabcd
--tags Key=Environment,Value=Production
02 Define the configuration parameters of your new snapshot lifecycle policy, required by the create-lifecycle-policy command. Create a new JSON document, name it lifecycle-policy-config.json, paste the content described below, then adjust the necessary parameters based on your EBS backup needs. The following example represents a simple snapshot lifecycle policy that configures Amazon DLM to take daily backups, at 4AM, for an EBS volume tagged with "Environment = Production" tag set, that implements a retention period of 7 days:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
{
"ResourceTypes": [
"VOLUME"
],
"TargetTags": [
{
"Key": "Environment",
"Value": "Production"
}
],
"Schedules":[
{
"Name": "DailySnapshots",
"CreateRule": {
"Interval": 24,
"IntervalUnit": "HOURS",
"Times": [
"04:00"
]
},
"CopyTags": false,
"RetainRule": {
"Count": 7
}
}
]
}
03 Run create-lifecycle-policy command (OSX/Linux/UNIX) using the policy definition created at the previous step (i.e. lifecycle-policy-config.json) as value for the --policy-details parameter and the ARN of the AWS-managed IAM role that has permissions to create, delete and describe volumes/snapshots, to create a snapshot lifecycle policy for the Amazon EBS volume tagged earlier in the process:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
aws dlm create-lifecycle-policy
--region us-east-1
--execution-role-arn arn:aws:iam::123456789012:role/service-role/AWSDataLifecycleManagerDefaultRole
--description "Snapshot lifecycle policy for production EBS volumes"
--state ENABLED
--policy-details file://lifecycle-policy-config.json
04 The command output should return the ID of the new Amazon DLM lifecycle policy:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
{
"PolicyId": "policy-01234abcd1234abcd"
}
05 If required, repeat steps no. 1 – 4 to create snapshot lifecycle policies for other Amazon EBS volumes available in the current region.
06 Change the AWS region by updating the --region command parameter value and repeat steps no. 1 – 5 for other regions.