turbot/aws_insights

Query: ec2_target_groups_for_ec2_instance

Usage

powerpipe query aws_insights.query.ec2_target_groups_for_ec2_instance

SQL

with aws_ec2_instances as (
select
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_group_arn,
target_health_descriptions,
account_id,
region
from
aws_ec2_target_group
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
)
select
target.target_group_arn
from
aws_ec2_instances as i,
aws_ec2_target_groups as target,
jsonb_array_elements(target.target_health_descriptions) as health_descriptions
where
health_descriptions -> 'Target' ->> 'Id' = i.instance_id;