turbot/aws_insights

Query: iam_roles_for_ec2_instance

Usage

powerpipe query aws_insights.query.iam_roles_for_ec2_instance

SQL

with aws_ec2_instances as (
select
instance_id,
iam_instance_profile_arn,
account_id,
region
from
aws_ec2_instance
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1
),
aws_iam_roles as (
select
instance_profile_arns,
arn,
account_id,
region
from
aws_iam_role
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
)
select
distinct r.arn as role_arn
from
aws_ec2_instances as i,
aws_iam_roles as r,
jsonb_array_elements_text(instance_profile_arns) as instance_profile
where
instance_profile = i.iam_instance_profile_arn;