You are writing a cleanup Lambda that deletes unattached EBS volumes. How do you avoid deleting something important?
IntermediateScenarioAWS automation with boto3
Answer
Situation read → "Unattached" (State=available) does not mean "unwanted".
What I'd do →
- Filter
status=available, then require a minimum age since detachment (CloudTrailDetachVolumetime or adetached-attag set by a first pass). - Skip volumes tagged
Retain=trueor owned by a known system. - Snapshot before deletion (tag the snapshot with source volume and date) for a recovery window.
- Run in report mode for two weeks before enabling deletion.
Why → A two-phase "mark, then sweep" design gives owners time to object.
Interview tip → "Mark and sweep with a grace period" is the pattern name to use.
More on AWS automation with boto3
You are asked to write a script that stops all dev EC2 instances at 8 PM and starts them at 8 AM. How do you build it?BeginnerA script that lists all S3 objects in a bucket reports 1,000 objects, but the console says there are 48,000. What happened, and how do you fix the script?BeginnerYou 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?IntermediateYour audit script hits `ThrottlingException` / `RequestLimitExceeded` when scanning large accounts. What do you change?AdvancedYou must audit 40 AWS accounts in an Organization from one script. How do you handle credentials?AdvancedA Lambda written in Python times out at 15 minutes while processing a big S3 prefix. What are your options?Advanced