Welcome to part 7 of tutorial series on Flask application with EC2 instance. In the previous tutorial, we have successfully created gunicorn as a service. In this tutorial, we will take the step further on how to route dot com traffic to our flask application hosted on EC2. We will cover the traffic route in two steps. As a first step, we will cover the creation of elastic IP (in this tutorial) and as the next step, we will route the traffic from dot com (in the next tutorial).
Ideally, we can use the current IPv4 public IP address to route traffic. So, why we require an Elastic IP? Generally, the current IPv4 public IP is randomly assigned to our instance and will change when you stop and start your instance. You might think that we will not restart the instance, but what if any failure occurs or some installation requires a reboot to take an effect. Hence, each time we have to change update the records and it’s not feasible. As a result, Elastic IP comes into the picture since it doesn’t change until we release the IP address. Elastic IP is nothing but the static or real IP address.
To create an Elastic IP, we will select the instance and click on Actions -> Networking -> Manage IP Addresses.
It will pop up a dialog box in which we will click on Allocate Elastic IP
In the next window, we will get two option that is Amazon pool (Allocate IP from its available pool) and Owned by me (Any EIP owned by the user). Here we will select the Amazon pool since we don’t own any EIP and click on allocate.
In the next screen it will show the EIP that is being allocated by Amazon Pool.
Note: You can also create EIP from Elastic IPs under NETWORK & SECURITY from the left panel. The above is one of the ways.
Till now we have only created the EIP, not yet associated. As a next step we will associate the IP address to an EC2 instance. From the console, we will click on Elastic IPs under NETWORK & SECURITY from the left panel. There we will see the EIP that we have just created. We will select that and click on Actions -> Associate address. It the next window we will associate the EIP to an instance using instance id as shown below.
Now, we can copy the Elastic IP and load it in the browser. Hence, we can see that the application is up and running. Previous Public IPv4 is now replaced by EIP. For more refer the video tutorial on the same.
In the next tutorial, I will take you through how to route traffic from domain to an EC2 instance. In a mean time refer my YouTube channel for more tutorials. Keep sharing and stay tuned for more. Follow me on Twitter