Rez Moss
Rez Moss

Reputation: 4600

How can I stop and start EC2 automatically, when it not responding on http

I have an EC2 with the HTTP server; I want to stop and start it automatically when it was not responding on HTTP port after 2 minutes.

What is the best way to implement on AWS without using the scale group and elastic load balancer(ELB).

As I mentioned before, I don't need to create the new instance, just stop and start.

Upvotes: 0

Views: 651

Answers (2)

caba
caba

Reputation: 476

I am using Route53 healthcheck which, when triggered, sends notification to SNS topic that triggers Lambda function that reboots the server.

Upvotes: 1

Madhan S
Madhan S

Reputation: 937

  • First instead of stopping and starting instance considering restarting service with help of monit or another monitoring service because restarting instance will take time and not a good idea.

  • But if you are worried about instance going down scenarios, you can configure auto healing(https://aws.amazon.com/blogs/aws/new-auto-recovery-for-amazon-ec2/).

  • Another custom way of doing would be, inside instance do a simple hello check using curl and store the response log and schedule it in a cron, Sync the log to cloudwatch and in cloudwatch you can plot metric using logs, and configure alarm if the metric count goes below a threshold for 2 mins, you can write lambda function to restart the instance, and associate the lambda to the alarm.(https://aws.amazon.com/premiumsupport/knowledge-center/start-stop-lambda-cloudwatch/). Since you have mentioned you are having one instance this approach will work, if you have more than one instance you need to handle namespace, But again restarting instance is a not a good idea.

Upvotes: 1

Related Questions