turbot/steampipe-mod-aws-compliance

Control: EC2 stopped instances should be removed in 30 days

Description

Enable this rule to help with the baseline configuration of AWS Elastic Compute Cloud (AWS EC2) instances by checking whether AWS EC2 instances have been stopped for more than the allowed number of days, according to your organization's standards.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.ec2_stopped_instance_30_days

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.ec2_stopped_instance_30_days --share

SQL

This control uses a named query:

select
arn as resource,
case
when instance_state not in ('stopped', 'stopping') then 'skip'
when state_transition_time <= (current_date - interval '30' day) then 'alarm'
else 'ok'
end as status,
case
when instance_state not in ('stopped', 'stopping') then title || ' is in ' || instance_state || ' state.'
else title || ' stopped since ' || to_char(state_transition_time , 'DD-Mon-YYYY') || ' (' || extract(day from current_timestamp - state_transition_time) || ' days).'
end as reason
, region, account_id
from
aws_ec2_instance;

Tags