How to Clean Up AWS Load Balancers
When compute instances are removed, their load balancers are sometimes left behind.
Fix Inventory's cleanup-aws-loadbalancers infrastructure app can find and delete these orphaned load balancers.
Prerequisites​
This guide assumes that you have already installed and configured Fix Inventory to collect your AWS resources.
Directions​
-
Execute the following command in Fix Inventory Shell to open the Fix Inventory Worker configuration for editing:
> config edit fix.worker -
Enable cleanup by modifying the
fixworkersection of the configuration as follows:fixworker:
# Enable cleanup of resources
cleanup: true
# Do not actually cleanup resources, just create log messages
cleanup_dry_run: false
# How many cleanup threads to run in parallel
cleanup_pool_size: 16When cleanup is enabled, marked resources will be deleted as a part of the
collect_and_cleanupworkflow, which runs each hour by default.tipSet
cleanup_dry_runtotrueto simulate cleanup without actually deleting resources. -
Use the
app installcommand to install thecleanup-aws-loadbalancersapp:> app install cleanup-aws-loadbalancersinfoFix Inventory will create a default config
fix.apps.cleanup_aws_loadbalancers. -
Execute the following command in Fix Inventory Shell to open the infrastructure app configuration for editing:
> config edit fix.apps.cleanup_aws_loadbalancers -
Update the configuration and set the
min_ageproperty to the desired threshold for load balancer cleanup:cleanup_aws_loadbalancers configurationmin_age: 7dnoteThe above infrastructure app configuration cleans up ELBs, ALBs, and ALB target groups older than the minimum age with no attached backends. Items tagged with
expiration: neverwill not be flagged for cleanup. -
Run the app using the
app runcommand:> app run cleanup-aws-loadbalancerstipAdd the optional
--dry-runflag to see what commands the app would perform, without actually executing them.noteItems tagged with
expiration: neverwill not be flagged for cleanup. -
Create an event-based job to run the app automatically:
> jobs create --name "Clean Up AWS Load Balancers" --wait-for-event cleanup_plan 'app run cleanup-aws-loadbalancers'infoThe
cleanup-aws-loadbalancersinfrastructure app will now run each time Fix Inventory emits thecleanup_planevent. Thepost_cleanup_planevent is emitted in thecleanupphase of thecollect_and_cleanupworkflow.
Each time the cleanup-aws-loadbalancers infrastructure app runs, orphaned load balancers will be flagged for removal during the next cleanup run.