--- name: aws-cost-cleanup description: Automated cleanup of unused AWS resources to reduce costs risk: safe source: community --- # AWS Cost Cleanup Automate the identification and removal of unused AWS resources to eliminate waste. ## When to Use This Skill Use this skill when you need to automatically clean up unused AWS resources to reduce costs and eliminate waste. ## Automated Cleanup Targets **Storage** - Unattached EBS volumes - Old EBS snapshots (>90 days) - Incomplete multipart S3 uploads - Old S3 versions in versioned buckets **Compute** - Stopped EC2 instances (>30 days) - Unused AMIs and associated snapshots - Unused Elastic IPs **Networking** - Unused Elastic Load Balancers - Unused NAT Gateways - Orphaned ENIs ## Cleanup Scripts ### Safe Cleanup (Dry-Run First) ```bash #!/bin/bash # cleanup-unused-ebs.sh echo "Finding unattached EBS volumes..." VOLUMES=$(aws ec2 describe-volumes \ --filters Name=status,Values=available \ --query 'Volumes[*].VolumeId' \ --output text) for vol in $VOLUMES; do echo "Would delete: $vol" # Uncomment to actually delete: # aws ec2 delete-volume --volume-id $vol done ``` ```bash #!/bin/bash # cleanup-old-snapshots.sh CUTOFF_DATE=$(date -d '90 days ago' --iso-8601) aws ec2 describe-snapshots --owner-ids self \ --query "Snapshots[?StartTime<='$CUTOFF_DATE'].[SnapshotId,StartTime,VolumeSize]" \ --output text | while read snap_id start_time size; do echo "Snapshot: $snap_id (Created: $start_time, Size: ${size}GB)" # Uncomment to delete: # aws ec2 delete-snapshot --snapshot-id $snap_id done ``` ```bash #!/bin/bash # release-unused-eips.sh aws ec2 describe-addresses \ --query 'Addresses[?AssociationId==null].[AllocationId,PublicIp]' \ --output text | while read alloc_id public_ip; do echo "Would release: $public_ip ($alloc_id)" # Uncomment to release: # aws ec2 release-address --allocation-id $alloc_id done ``` ### S3 Lifecycle Automation ```bash # Apply lifecycle policy to transition old objects to cheaper storage cat > lifecycle-policy.json <