Day 20–101 Days of DevOps — Creating and Deleting Snapshots using Boto3
Welcome to Day 20 of 101 Days of DevOps. The topic for today is Creating and deleting snapshots using Boto3.
To view the complete course, please check the below url.
For more info, register via the below link
YouTube Channel link
This is another common use case we use to encounter daily DevOps jobs where we need to create and clean up snapshots per company policy(e.g., every 30 or 60 days). One of the primary reasons to create snapshot is for backup, and cleanup is to save costs.
To write this code, we need to follow the series of steps
Step1: Importing the standard library boto3
import boto3
Step2: Create the ec2 resource.
ec2 = boto3.resource("ec2")
Step3: Iterate over all the ec2 volumes to get the volume id and stored it in the volume variable.
for vol in ec2.volumes.all():
vol_id = vol.id
volume = ec2.Volume(vol.id)
Step4: To create a snapshot, we need to use the create_snapshot() method.
volume.create_snapshot(Description=desc)
Deleting snapshots is similar to how we perform cleaning up AMI on Day 19(obviously, the method we use to delete snapshots is different)https://www.101daysofdevops.com/courses/101-days-of-devops/lessons/day-19/. I already explain the process in the below video, but please mention it in the comment section if you need any help.
If you like to dig deeper into the AWS concept, please feel free to check my book
GitHub link
Please join me with my journey by following any of the below links
- Website: https://101daysofdevops.com/
- Linkedin: https://www.linkedin.com/in/prashant-lakhera-696119b/
- Twitter: @100daysofdevops OR @lakhera2015
- Facebook: https://www.facebook.com/groups/795382630808645/
- Medium: https://medium.com/@devopslearning
- GitHub: https://github.com/100daysofdevops/100daysofdevops
- YouTube Channel: https://www.youtube.com/user/laprashant/videos
- Slack: https://join.slack.com/t/100daysofdevops/shared_invite/zt-au03logz-YfDUp_FJF4rAUeDEbgWmsg
- Reddit: r/101DaysofDevops
- Meetup: https://www.meetup.com/100daysofdevops/