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

Feature/get platform from instance info #22

Closed GlennChia closed 2 years ago

GlennChia commented 2 years ago

Issue #, if available: Closes #23

Description of changes:

There could be cases where the base AMI is unavailable (e.g. EC2 instance restored from a AWS Backup Recovery point that has since exceeded its Retention period, or an EC2 instance that was launched from an AMI that has since been deregistered).

This PR adds additional logic to retrieve the Platform details from the instance_info should they be unavailable from the image information. The describe_instances API call provides the PlatformDetails response to achieve this.

Note that Ubuntu and Amazon Linux platforms cannot be distinguished. Both return Linux/UNIX. Hence, they are not handled by this PR. This PR does however, handle Windows, Red Hat, and SUSE platforms since their Platform Details are specific.

Also adding an additional fix for detecting if ubuntu is in the image Description. Since the Description attribute is optional, this PR adds a check if it exists first before checking if ubuntu is a sub-string within it.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.