0

I set up a per-instance CPUUtilization alarm on CloudWatch, which appears to require an instance ID.

  1. How do you add a per-instance alarm on instances that have been created with auto scaling? I would not know the instance ID or even that the instance has been created.

  2. If I create an alarm for the instance after it is created, when the instance is terminated, the alarm remains with "INSUFFICIENT DATA".

B Seven
  • 101
  • 2
  • Probably with Lambda, iterating through instances available and maybe looking at the tags. You can do most things in AWS with Lambda, though it's not always the most efficient way, I haven't done much in this area so can't give you much advice. – Tim Aug 20 '19 at 07:44

1 Answers1

1

You can invoke a Lambda function through CloudWatch event rules to manage your alarms.

Create an event rule for the following autoscaling events:

  • RunInstances
  • TerminateInstances

Register your Lambda function as the target for these events, which fetches the InstanceId(s) from the event data and creates or deletes alarms accordingly.

Below is a sample event rule description for RunInstances event.

{
"source": [
    "aws.ec2"
],
"detail-type": [
    "AWS API Call via CloudTrail"
],
"detail": {
    "eventSource": [
        "ec2.amazonaws.com"
    ],
    "eventName": [
        "RunInstances"
    ],
    "userAgent": [
        "autoscaling.amazonaws.com"
    ]
  }
}

It is also possible to use Lifecycle hooks, but CloudWatch events is a better fit for this use-case.

Vikyol
  • 161
  • 4