How to Clean Up AWS CloudWatch Alarms
When deleting EC2 instances, AWS CloudWatch instance alarms are sometimes left behind.
Fix Inventory's cleanup-aws-alarms
infrastructure app can find and delete these orphaned alarms.
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
fixworker
section 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_cleanup
workflow, which runs each hour by default.tipSet
cleanup_dry_run
totrue
to simulate cleanup without actually deleting resources. -
Use the
app install
command to install thecleanup-aws-alarms
app:> app install cleanup-aws-alarms
infoFix Inventory will create a default config
fix.apps.cleanup_aws_alarms
. -
Execute the following command in Fix Inventory Shell to open the infrastructure app configuration for editing:
> config edit fix.apps.cleanup_aws_alarms
-
Update the configuration with the desired target cloud account IDs:
cleanup_aws_alarms configurationclouds_and_accounts:
aws:
- '1234567'
- '567890' -
Run the app using the
app run
command:> app run cleanup-aws-alarms
tipAdd the optional
--dry-run
flag to see what commands the app would perform, without actually executing them.noteItems tagged with
expiration: never
will not be flagged for cleanup. -
Create an event-based job to run the app automatically:
> jobs create --name "Clean Up AWS Alarms" --wait-for-event cleanup_plan 'app run cleanup-aws-alarms'
infoThe
cleanup-aws-alarms
infrastructure app will now run each time Fix Inventory emits thecleanup_plan
event. Thepost_cleanup_plan
event is emitted in thecleanup
phase of thecollect_and_cleanup
workflow.
Each time the cleanup-aws-alarms
infrastructure app runs, orphaned CloudWatch alarms will be flagged for removal during the next cleanup run.