Interview Prep/Python for DevOps/AWS automation with boto3

You need to find and delete EBS snapshots older than 90 days, but some are used by AMIs and backup plans. How do you write it safely?

IntermediateScenarioAWS automation with boto3
Answer

Situation read → Old snapshot cleanup with dependencies; deleting the wrong one breaks AMIs or compliance retention.

What I'd do →

  1. List with describe_snapshots(OwnerIds=["self"]) paginator; filter StartTime < now - 90d using timezone-aware datetimes.
  2. Exclude snapshots referenced by registered AMIs (describe_images(Owners=["self"]), collect BlockDeviceMappings[].Ebs.SnapshotId).
  3. Exclude snapshots managed by AWS Backup or DLM (tags like aws:backup:source-resource or dlm:managed) and anything tagged Retain=true.
  4. Dry-run report first; delete with delete_snapshot, handling InvalidSnapshot.InUse as skip, not failure.
  5. Long term, let DLM or AWS Backup own retention.

Why → Delete only what you can prove is unowned.

Interview tip → Mentioning the AMI cross-check shows you have actually done this.

All Python for DevOps questions Roadmap: Python for automation

More on AWS automation with boto3