Day 18- Automate the EBS Snapshot and AMIs creation using Amazon Data Lifecycle Manager
Welcome to Day 18 of 100 Days of AWS. The topic for today is Automate the EBS Snapshot and AMIs creation using Amazon Data Lifecycle Manager
What are EBS Snapshots?
- Snapshots are a point in time backups of modified EBS Volumes stored in S3.
- They are incremental, i.e., the first snapshot is the complete backup of your Volume, but all the subsequent snapshot is just an incremental change.
- We can use snapshots to create an AMI.
- Mostly used for a backup purpose to fully restore your EBS Volumes.
- The recommendation is to frequently take snapshots depending upon your Recovery Time Objective(RTO)
- For data consistency, it’s good to stop any write operation before performing snapshots.
Data Life Cycle Manager
Data Life Cycle Manager is an easy an automated way to backup and delete data stored on EBS.
- You can define policies to enforce backup on regular schedule.
- Use of tag to identify volumes and instance defined in the policies
- Manage cost by deleting snapshots
Go to AWS → Compute → EC2 → Elastic Block Store → Lifecycle Manager → Create Snapshot Lifecycle Policy. Click on Next step
- In the next screen, you have an option to take snapshot of specific Volume by specifying the tag or at instance level which will take snapshot of all the EBS volumes associated with the instance(In the bottom you have an option to exclude root volume)(don’t Forget to click on Add). Give your policy description and select the Default role. Make sure policy status is Enabled. Click on Next.
- In the next screen give your Schedule name, you can select the Frequency(Daily, Weekly, Monthly, Yearly or Custom cron expression). You can schedule this snapshot every (1,2,3,4,6,8,12,24 hour). Specify the starting time(NOTE timing is in UTC, so please adjust it based on the requirement as you don’t want your snapshot to be happen during Production hour). Last you can specify how many copies of snapshot you want to maintain. Copy tags from source check this option so that snapshot will have same tag as your instance tag. In the next screen, click on Create policy.
NOTE: You need to wait atleast 1hour after configuring the snapshot. If you want to create snapshot more frequently you need to write your own custom lambda function. Click Review policy
- Now if you go to the EC2 console and click on Snapshots, you will see the snapshots created by the policy.
- Automating the process of AMI creation is similar to EBS Snapshot. For AMI creation from the drop-down choose EBS-backed AMI policy.
- The first few steps is similar to snapshot creation, select the Target resource tags, give your policy name, make sure policy status is enabled. Choose Instance reboot as no
NOTE: Selecting No may cause data consistency issues. Choose Yes to reboot instances before AMI creation. But this is all depend upon your requirement and definitely Yes is not recommended for production environment.
- Define the schedule, similar to we defined for Snapshot creation, review the policy and create it.
- It also provides monitoring via CloudWatch for your policy.