turbot/aws_insights

Query: ec2_network_load_balancers_for_ec2_instance

Usage

powerpipe query aws_insights.query.ec2_network_load_balancers_for_ec2_instance

SQL

with aws_ec2_instances as (
select
arn,
instance_id,
account_id,
region
from
aws_ec2_instance
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1
),
aws_ec2_target_groups as (
select
target_health_descriptions,
load_balancer_arns,
account_id,
region
from
aws_ec2_target_group
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
),
aws_ec2_network_load_balancers as (
select
arn,
account_id,
region
from
aws_ec2_network_load_balancer
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
)
select
distinct lb.arn as gateway_load_balancer_arn
from
aws_ec2_instances as i,
aws_ec2_target_groups as target,
jsonb_array_elements(target.target_health_descriptions) as health_descriptions,
jsonb_array_elements_text(target.load_balancer_arns) as l,
aws_ec2_network_load_balancers as lb
where
health_descriptions -> 'Target' ->> 'Id' = i.instance_id
and l = lb.arn;