Day 20–101 Days of DevOps — Creating and Deleting Snapshots using Boto3

Prashant Lakhera
2 min readJul 21, 2021

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

--

--

Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP