How to delete AWS CloudWatch alarm during EC2 termination - amazon-web-services

I would like to delete attached AWS CloudWatch alarm of an EC2 instance during the termination and also based on specific tags. Because we will have large number of EC2 in our account.
Example: I would like to delete CloudWatch alarm of EC2 instances during its termination which has Tag (name:id,Value:123).

Related

AWS Cloudwatch alarm - change in instance id

I am new to AWS & have configured a Cloudwatch alarm to reboot an EC2 instance, if its StatusCheckFailed fails.
The issue is that, I frequently make updates to the image AMI and need to terminate the old instance and re-launch it with new AMI.
This results in instance id getting changed and thus, the Cloudwatch alarm I initially created (with reference to instance-id)becomes outdated.
What is the best practice to keep the Cloudwatch alarm updated, when the instance-id changes ?

Setup CloudWatch Alarms for EC2 instances in Autoscaling Group(CF)

I have an AWS::AutoScaling::AutoScalingGroup configuration that runs two instances of EC2. My question is - is it possible to attach CloudWatch alarms for both instances? For example I want to observe StatusCheckFailed_Instance metric for each EC2 in a group?
Usually you can attach alarms through the EC2 Instance ID but how to know each EC2 Instance ID in AutoScalingGroup to attach alerts? or here should be another way to attach alerts? I really can't find something useful and workable over internet.
Option 1)
Create your own script that's triggered on launch/terminate events
the scripts will each be set to trigger a lambda that would read in the instance ID and create/delete an alarm
Option 2)
If you're not trying to use the auto-recover option (which you shouldn't need in an ASG, since the ASG will just replace the instances), then you can make 1 aggregate alarm for the ASG
Create the alarm based on the StatusCheckFailed_Instance metric with the ASGName=<> Dimension
Set it to trigger if the MAX statistic value is > 1 (since that means at least 1 instance is failing, each instance will push its own datapoints to ASG versions of EC2 metrics)
Since you only have 2 instances, you can just manually check both if it ever triggers. But for larger ASGs using the SEARCH() math expression on the CloudWatch metrics console (or a dashboard) would be a good way to look through all the ASG instances and view their metrics to see which one is failing

AWS Cloudwatch Alarm not stopping EC2 instance

I have created an alarm in Cloudwatch to stop my EC2 instance, if the CPU < 5% for more than five minutes.
And after five minutes I get the email but the instance continues running. The instance is using an EBS volume and nothing in the history indicates a problem.
Can someone please tell me why the alarm I setup is not stopping the instance?
Thanks
According to the documentation, you need to create an IAM role so that AWS can automatically stop the instance on your behalf when the alarm is triggered. Also note that you cannot assign an IAM role to an existing instance.
Update:
You can now attach to or modify an IAM role of your existing instance. Read more here.
I am new to aws part,hope this may help...not sure...
Amazon EBS may not send metric data for an available volume that is not attached to an Amazon EC2 instance, because there is no metric activity to be monitored for that volume. If you have an alarm set for such a metric, you may notice its state change to Insufficient Data. This may simply be an indication that your resource is inactive, and may not necessarily mean that there is a problem.

cloudwatch alarm for Autoscaling

how to setup cloudwatch alarm for Autoscaling group when its scaling down Mincapacity Instances using cloudformation template.
I mean need alarm when all the Instances were "OutofService" basically this will happen when Instance failed ELB healthcheck.
Why don't you add an alarm based on the CloudTrail metric HealtlyHostCount? If you set a low threshold, you will get warned when there are no healthy instances.
You can see the metrics documentation here

How do I create email alerts for instance stop, start, termination in AWS?

How do I create email alerts for instance stop, start, termination
in AWS?
Using Amazon CloudWatch alarm actions, you can create alarms that automatically stop, terminate, reboot, or recover your Amazon Elastic Compute Cloud (Amazon EC2) instances.
For more details read link