aws-samples / amazon-cloudwatch-auto-alarms

Automatically create and configure Amazon CloudWatch alarms for EC2 instances, RDS, and AWS Lambda using tags for standard and custom CloudWatch Metrics.
MIT No Attribution
91 stars 85 forks source link

Check Platform from instance_info if image_info is unavailable #23

Closed GlennChia closed 2 years ago

GlennChia commented 2 years ago

Problem

Alarms creation depends on finding out the Platform for the EC2 instance. Within the code, there is a call made to describe_images to extract the Platform. This is dependent on the AMI still being available in the account. There could be the following cases (not exclusive) which render AMIs unavailable

  1. EC2 instance restored from a AWS Backup Recovery point that has since exceeded its Retention period
  2. EC2 instance that was launched from an AMI that has since been deregistered

This results in the following shown in the console:

Screenshot 2022-08-17 at 1 02 40 AM

The code then sets Platform as None which means no alarms are created.

Proposal

In the event when image_info is unavailable, we can still attempt to extract the platform from instance_info since the API contains information regarding it: EC2 describe_instances.

Reference PR: #22

Limitation

This only works for Windows, Red Hat, and SUSE platforms. The API does not return information to determine whether the EC2 instance is an Ubuntu or Amazon Linux platform since both return Linux/UNIX. Hence in the latter case, users are encouraged to either ensure the AMI description or name has ubuntu inside. If that is not possible, they will have to further customize the code to perhaps extract the Platform from a Tag that they create and design on the EC2 instance