library
turbot/aws_thrifty

Detect & correct EC2 application load balancers if unused

Amazon EC2 application load balancers with no targets attached still cost money and should be deleted. This query trigger identifies EC2 application load balancers with no targets attached and either sends notifications or attempts predefined corrective actions.

Getting Started

By default, this trigger is disabled, but can be configured by setting the variables:

  • ec2_application_load_balancers_if_unused_trigger_enabled should be set to true (default is false).
  • ec2_application_load_balancers_if_unused_trigger_schedule should be set according to your desired running schedule.
  • ec2_application_load_balancers_if_unused_default_action should be set to "notify" or any other desired action (e.g., "notify" for notifications or "delete_load_balancer" to delete the application load balancers).

Then starting the server:

flowpipe server

or if you've set the variables in a .fpvars file:

flowpipe server --var-file=/path/to/your.fpvars

Query

with target_resource as (
select
load_balancer_arn,
target_health_descriptions,
target_type
from
aws_ec2_target_group,
jsonb_array_elements_text(load_balancer_arns) as load_balancer_arn
)
select
concat(a.name, ' [', a.region, '/', a.account_id, ']') as title,
a.arn,
a.region,
a._ctx ->> 'connection_name' as cred
from
aws_ec2_application_load_balancer a
left join target_resource b on a.arn = b.load_balancer_arn
where
b.load_balancer_arn is null

Schedule

15m