1
votes

I am trying to create a Cloudwatch Rule that sends an EC2 instance's name (NOT the InstanceID) to SNS upon termination of the instance. The below snippet is the default event pattern that AWS provided when I chose to create this simple rule, but I added 1 section to the "detail-type" object. This section is "Instance Name". That did not work as the SNS email I received still did not include the instance's name. It only included the InstanceID within the message.

   {
  "source": [
    "aws.ec2"
  ],
  "detail-type": [
    "Instance Name",
    "EC2 Instance State-change Notification"
  ]
}

So far, I've only been successful with acquiring the InstanceID from the Cloudwatch Rule. Is the custom metadata from Tags possible to retrieve via Cloudwatch?

That being said, if it's not possible through Cloudwatch, is it possible to somehow send the SNS topic to Lambda, and convert the instanceID into the instance name using a Lambda function?

The whole point of my project here is so that I can use Lambda to run a script that removes these instances from a monitoring application once they are terminated. And outside of AWS, we use their Name to identify them, and not their instanceID.

1

1 Answers

4
votes

It's not possible to get CloudWatch to send more info to SNS. You would need to subscribe a Lambda function to the SNS topic. Inside the Lambda function you would need to make an AWS API call, with the instance ID from the CloudWatch message, to get the tags for the instance.