INF-54Recommended
Delete resources that sit idle
Run a weekly job that lists idle resources and deletes them after their owner has had 7 days to object. Snapshot every disk before the job deletes it, and never let it touch backups.
How to do it
List disks attached to nothing, unused public addresses and load balancers with no targets. Add servers stopped for 14 days, and snapshots older than 90 days that no backup plan made. Skip every resource tagged purpose = backup or purpose = dr. Backups expire by their own retention in the backup plan, never by this job. Before the job deletes a disk, it takes a final snapshot and keeps it for 30 days. Deletion protection from Protect resources that hold data stays on, so the job never removes a database. Tell the owner from the tags. Stop development servers at night and on weekends. Set lifecycle rules on buckets, so old files move to cheaper storage or expire. Remove the DNS records that pointed at them, as Remove DNS records you no longer use says.
Examples
Python example
import boto3
ec2 = boto3.client("ec2")
volumes = ec2.describe_volumes(Filters=[{"Name": "status", "Values": ["available"]}])["Volumes"]
for volume in volumes:
owner = next((t["Value"] for t in volume.get("Tags", []) if t["Key"] == "owner"), "no owner")
print(volume["VolumeId"], volume["Size"], "GiB", owner)
addresses = [a["PublicIp"] for a in ec2.describe_addresses()["Addresses"] if "AssociationId" not in a]
print("Unused addresses:", addresses)
JavaScript example
import { EC2Client, DescribeVolumesCommand, DescribeAddressesCommand } from '@aws-sdk/client-ec2';
const ec2 = new EC2Client({});
const { Volumes } = await ec2.send(new DescribeVolumesCommand({ Filters: [{ Name: 'status', Values: ['available'] }] }));
for (const volume of Volumes) {
const owner = volume.Tags?.find(tag => tag.Key === 'owner')?.Value ?? 'no owner';
console.log(volume.VolumeId, volume.Size, 'GiB', owner);
}
const { Addresses } = await ec2.send(new DescribeAddressesCommand({}));
console.log('Unused addresses:', Addresses.filter(address => !address.AssociationId).map(address => address.PublicIp));
How to check
The weekly report lists no resource that was already on last week's report and had no objection. In a sandbox, an idle disk tagged purpose = backup survives the job. An untagged idle disk is gone, and its final snapshot exists.
Sources
Related rules
- INF-8 Protect resources that hold data in Infrastructure and environments
- APS-68 Remove DNS records you no longer use in Application security
- INF-69 Track carbon per request beside cost in Infrastructure and environments
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/cost-and-ownership/delete-idle-resources">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.