Create cloudwatch alarm for Autoscaled EC2

755 views
Skip to first unread message

west...@gmail.com

unread,
Jun 9, 2017, 5:52:42 AM6/9/17
to Terraform
Hi Guys,

Does anyone know a way that i can get a cloudwatch alarm created for a new EC2 that is created via autoscaling launch configuration?

I am able to do this from terraform when i create an EC2 in the usual way.  When running a TF apply the cloudwatch alarm gets created after the EC2 but autoscaling is all triggered within AWS. Doesn't look as though it can be done right?

Mike

Brian Lalor

unread,
Jun 9, 2017, 5:56:51 AM6/9/17
to terrafo...@googlegroups.com
Have you tried using the depends_on meta-parameter? https://www.terraform.io/docs/configuration/resources.html#explicit-dependencies

signature.asc

west...@gmail.com

unread,
Jun 13, 2017, 2:37:49 PM6/13/17
to Terraform
Thanks Buddy, no haven't. I'll look into that

Phil S

unread,
Jun 18, 2017, 1:45:10 AM6/18/17
to Terraform
Hi Mike,

There's a few ways you could do this I can think of.

1. Autoscale groups provide 'rolled up' metrics for the instances attached to them.  For example, you could get average CPU across all instances in the ASG.  Alternatively, you can get a metric per-AZ for all instances in the ASG (e.g. average CPU of instances on that ASG in ap-southeast-2a or ap-southeast-2b).  So as long as you were happy to set an alarm on a group of instances, it might work.  e.g. if you just want to check for CPUCredit dropping too low, your alarm could be in 'Min' which would be the lowest of all the instances.

2. If the launched instance had an instance profile attached, the instance could create the alarm itself on boot.  You'd need to put it into the userdata and call the CLI commands, for example.

3. You could configure the ASG to send a launch notification to an outside component (e.g. lambda function) that would then create the alarm.

Hope that helps.

Phil
Reply all
Reply to author
Forward
0 new messages