How to send an alarm to AWS Cloudwatch from EC2 when your Nginx stops

Is there anyway to send an alarm to AWS Cloudwatch from EC2 when Nginx stops?

You might want to check out Route 53 healthchecks to see if they fulfill your use-case

As said, you can use/try R53 to send a ping to a webpage and generate alert if the ping fails. you can configure the http conditions.

You don’t have to have domains hosted in R53 to be able to healthcheck them (although the cost for doing on non-R53 domains is a tiny bit higher)

Another way could be to install the CloudWatch agent on the EC2 instance, and forward the nginx logs to CloudWatch.

Based on the service stopped log, you can create a metric filter, and then trigger an alarm.

I do agree this would be much better served by monitoring for service availability from outside the instance.

You could also look into CloudWatch Synthetics

I guess the only downside to that approach is that if the CW agent process fails/machine locks up it’s not going to send an alarm, whereas R53 healthchecks are isolated from that SPoF.

Another option: and execute a small script to put an cw alarm