Automating Creation And Deletion Of EBS Snapshots

In this blog , We will learn to configure data lifecycle manager for automating creation and deletion of EBS Snapshots

What Is Data Lifecycle Manager?

Amazon’s Data Lifecycle Manager provides us an automated procedure to backup the data of EBS volume.

Using this feature, You can managed the creation , Retention and deletion of the EBS snapshots in an automated way.

Creating Data Lifecycle Manager

To create DLM , Login to AWS EC2 CONSOLE ,

Under Elastic Block Storage , Click Lifecycle manager

You should see the following page.

Click Create Snapshot Lifecycle Policy

Here we are going to create a policy.

Provide a Description for the policy.

Next We have to select the resource type.

If the Resource type is Volume , You can schedule snapshots of the volumes with the specific tag. So Make sure you volumes are tagged properly before choosing this option

If the Resource Type is Instance , It will take the snapshot of all the volumes attached to the EC2 Instance.

You can add a Tag to the Lifecycle policy itself.

Under Policy Schedule ,

We are going to configure when this policy should run and how often it should run and what should be the retention for the snapshots.

Provide a name for the Schedule.

Next Run policy every , Mention how often this policy should run.

Lets configure it to run for every 24 hours.

And you can mention the time , the snapshot should start to create.

For Retention type ,

Retention type can be either the Count or the Age.

If you select Count , It means how many snapshots you want to keep.The oldest snapshot beyond this number will be deleted.

For example , I have mentioned to keep the 7 latest snapshots.

If you select Age , The snapshot will be deleted in the period of days from the time of creation.

In the above example , The snapshot will be deleted after 55 days.

Under Tagging information,

You can check Copy tags from volume , If you want the snapshots to have the same tags of the volume.

You can optionally enable Fast Snapshot Restore , and you will be charged additionally for this feature.

You can copy these snapshots to another region , By enabling Cross region copy.

You can choose the region where these snapshots should be copied and you can set the retention period for those snapshots as well.

Also You can configure send the snapshots to Multiple regions.

Under IAM Role , We have to grant permission for this pollicy to create and manage snapshots of the EBS volume.

permissions should involve,

"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:DescribeSnapshots",
"ec2:DescribeInstances",
"ec2:DescribeVolumes",
"ec2:DeleteSnapshot"

If you dont have an IAM Role , It will be created automatically with all the permissions.

If you have an existing role , You can select it.

You can set the status of the policy after Creation. Either you can Enable or Disable it.

Let us set the state of the policy to Enable after creation.

And finally Click Create policy.

The policy is created successfully and you will get id for each policy you create.

Conclusion

We have successfully created a policy which will Back up , Manage and Retention of the EBS volume Snapshots.

I hope you have learnt and found it helpful.

Thanks for reading this article.

Please do check out my other publications.