0
votes

I want to create CloudWatch alarms automatically on instance launch (via AutoScaling, CLI or whatever).

My instances are running Windows, so I created task in Task Scheduler which executes PowerShell script.

This script uses Write-CWMetricAlarm cmdlet to create CloudWatch Alarms - http://prntscr.com/e6xptj

It works good for custom Metrics like Windows/Default , but for AWS/EC2 Instance­Name is required as well - http://prntscr.com/e6xq18

But there's no Dimension for Instance­Name - http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html

.. as well as no suitable parameter for Write-CWMetricAlarm Cmdlet - http://docs.aws.amazon.com/powershell/latest/reference/Index.html

So any ideas about how this issue can be solved?

Thanks in advance!

1

1 Answers

1
votes

Instance names are actually just tags (with key "Name") and the console gives them special treatment to make them appear as a first-class item. They also do not need to be unique, so using 'name' wouldn't enable CloudWatch to distinguish between different instances, making things confusing from an alarm perspective.

I think therefore that you need to be using the instance id value. In your script I notice you're using Invoke-Restmethod to obtain it - you might be interested to know you can also get this value using a cmdlet:

Get-EC2InstanceMetadata -Category InstanceId