<p>What you are talking about is known as a health check. Typically these are handled by load balancers, to decide whether instances are "healthy", and thus can serve (usually HTTP) traffic. The load balancers will poll and endpoint that you define to decide whether the instances are healthy, usually by seeing if the HTTP response code is some known-good one, like 200.</p>

<p>One solution therefore, could be to front your application with a load balancer, and enable <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-healthchecks.html" rel="nofollow noreferrer">health checks</a> on the relevant urls. This will check whether your application is serving traffic properly, when polled by the load balancer. While this adds a level of complexity (and cost) to the app, it is also quite easy to do.</p>

<p>Of course, you could mimic this functionality without an AWS load balancer, by having your app poll the url that the app is supposed to respond on, by using the DNS or IP name returned by AWS after the instance becomes "running". </p>

<p>Another option would be to set up an actual monitoring system to check whether the application is serving content. A very simple and free tool that would do the job is <em>e.g.</em> <a href="https://www.freshworks.com/website-monitoring/" rel="nofollow noreferrer">Freshping</a>.</p>

<p>You could also write an <a href="https://www.inspec.io/docs/reference/profiles/" rel="nofollow noreferrer">Inspec Compliance profile</a> to describe a known good state of the machine. Inspec can connect to the machine via SSH, which you specify as being open. This may sound like overkill, and quite similar to the ICMP test you considered before, but it's nevertheless an option :)</p>

CC BY-SA 4.0
2019-12-08T16:55:57.377Z
Thanks Bruce, that was exactly what I was looking for!
Javier Rodriguez
CC BY-SA 4.0
2019-12-04T08:40:22.677Z
2019-12-04T08:47:34.027Z
2019-12-04T08:47:34.027Z
Bruce Becker
<p>Recently I was playing around a bit with AWS as a part of a course that I am doing. I came across a situation that to be honest is keeping be in vilo.</p>

<p>I made a web application which connects to a backend that basically launches a EC2 t2.micro instance on AWS. From time to time, I pull the status of the machine to check whether it is on <code>running</code> state or note. The AMI I am using it is a configured wordpress from the marketplace.</p>

<p>As soon as the instance gets to the <code>running</code> state, I show a message indicating the server is up and running and provide the user with the instance's public ip address, the problem is that, it is not after a few minutes later when indeed the IP is resolved/accessible. The security group attached to the instance has the inbound and outbound traffic configured to allow TCP traffic on port 80, 22 and 443.</p>

<p>My question is, the <code>running</code> state simply means the instance is ready to work but, as far as I know, it does not mean OS has booted nor the X application (in this case wordpress and its configured server) are ready to or finished the bootstrapping. How can I check that indeed the application/OS has booted is I can ensure that when the user is trying to access the IP it will not timeout.</p>

<p>My first attempt was to ping the instance bu to be honest I don't think it's a reliable request since, I'd also need to enable the ICMP protocol but at the end, it's working in another internet layer.</p>

<amazon-web-services><amazon-ec2>
How to ensure EC2's OS/application is loaded?
Javier Rodriguez
# How to ensure EC2's OS/application is loaded?

(Asked by: username_0 on 2019-12-04)

Recently I was playing around a bit with AWS as a part of a course that I am doing. I came across a situation that to be honest is keeping be in vilo.

I made a web application which connects to a backend that basically launches a EC2 t2.micro instance on AWS. From time to time, I pull the status of the machine to check whether it is on `running` state or note. The AMI I am using it is a configured wordpress from the marketplace.

As soon as the instance gets to the `running` state, I show a message indicating the server is up and running and provide the user with the instance's public ip address, the problem is that, it is not after a few minutes later when indeed the IP is resolved/accessible. The security group attached to the instance has the inbound and outbound traffic configured to allow TCP traffic on port 80, 22 and 443.

My question is, the `running` state simply means the instance is ready to work but, as far as I know, it does not mean OS has booted nor the X application (in this case wordpress and its configured server) are ready to or finished the bootstrapping. How can I check that indeed the application/OS has booted is I can ensure that when the user is trying to access the IP it will not timeout.

My first attempt was to ping the instance bu to be honest I don't think it's a reliable request since, I'd also need to enable the ICMP protocol but at the end, it's working in another internet layer.

**Tags:** amazon-web-services, amazon-ec2


---

## 1 answers

### Answer by username_1 on 2019-12-04. Score: 0 | Accepted answer

What you are talking about is known as a health check. Typically these are handled by load balancers, to decide whether instances are "healthy", and thus can serve (usually HTTP) traffic. The load balancers will poll and endpoint that you define to decide whether the instances are healthy, usually by seeing if the HTTP response code is some known-good one, like 200.

One solution therefore, could be to front your application with a load balancer, and enable [health checks](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-healthchecks.html) on the relevant urls. This will check whether your application is serving traffic properly, when polled by the load balancer. While this adds a level of complexity (and cost) to the app, it is also quite easy to do.

Of course, you could mimic this functionality without an AWS load balancer, by having your app poll the url that the app is supposed to respond on, by using the DNS or IP name returned by AWS after the instance becomes "running".

Another option would be to set up an actual monitoring system to check whether the application is serving content. A very simple and free tool that would do the job is *e.g.* [Freshping](https://www.freshworks.com/website-monitoring/).

You could also write an [Inspec Compliance profile](https://www.inspec.io/docs/reference/profiles/) to describe a known good state of the machine. Inspec can connect to the machine via SSH, which you specify as being open. This may sound like overkill, and quite similar to the ICMP test you considered before, but it's nevertheless an option :)

> **Comments:**
> **username_0**: Thanks Bruce, that was exactly what I was looking for!  

---

