library
turbot/aws_thrifty

Detect & correct EC2 instances of older generation

Overview

Older generation instance types are more expensive and less performant than the current generation equivalents, you should be using the latest generation to reduce costs and increase performance.

This pipeline detects older generation EC2 instances and then either sends a notification or attempts to perform a predefined corrective action.

Getting Started

This control will work out-of-the-box with some sensible defaults (configurable via variables).

You should be able to simply run the following command in your terminal:

flowpipe pipeline run detect_and_correct_ec2_instances_of_older_generation

You should now receive notification messages for the detections in your configured notifier.

However, you may want to actually perform an action against these resources beyond a simple notification.

Interactive Decisions

Through the use of an Input Step, you can make a decision on how to handle each detected item.

In order to acheieve this, you will need to have an instance of Flowpipe Server running:

flowpipe server --mod-location=/path/to/mod

or if the current working directory contains the mod, simply:

flowpipe server

You can then run the command below:

flowpipe pipeline run detect_and_correct_ec2_instances_of_older_generation --host local --arg='approvers=["default"]'

This will prompt for an action for each detected resource and then attempt to perform the chosen action upon receipt of input.

You can also decide to bypass asking for decision and just automatically apply the same action against all detections.

Automatic Actioning

You can automatically apply a specific action without the need for running a Flowpipe Server and asking for a decision by setting the default_action parameter:

flowpipe pipeline run detect_and_correct_ec2_instances_of_older_generation --arg='default_action="terminate_instance"'

However; if you have configured a non-empty list for your approvers variable, you will need to override it as below:

flowpipe pipeline run detect_and_correct_ec2_instances_of_older_generation --arg='approvers=[]' --arg='default_action="terminate_instance"'

This will attempt to apply the action to every detected item, if you're happy with this approach you could have this occur mmore frequently by either scheduling the command by yourself or enabling the associated Query Trigger.

Query

select
concat(instance_id, ' [', region, '/', account_id, ']') as title,
instance_id,
region,
_ctx ->> 'connection_name' as cred
from
aws_ec2_instance
where
instance_type like 't2.%'
or instance_type like 'm3.%'
or instance_type like 'm4.%'

Schedule

15m