How to serve traffic from AWS EC2 instance

When you start your EC2 instance, EC2 automatically installs the operating system (Linux or Microsoft Windows). But you will need to install your web-server on the instance.

If you’’re hosting a website or running a web application on an EC2 instance, you can route traffic of your domain to your server using Amazon Route 53.

It is recommended to create an Elastic IP address and associate it with your EC2 instance. An Elastic IP address ensures that the IP address of your Amazon EC2 instance will never change. If you registered the domain name via Amazon Route 53, it will be automatically configured at Amazon Route 53 as the DNS service for the domain.

To configure Amazon Route 53 to route traffic to an EC2 instance, perform the following procedure.

Configure traffic to be routed to an Amazon EC2 instance:

  • Get the IP address for the Amazon EC2 instance. See P.S.1 below as to how to do this
  • Open the Amazon Route 53 console at https://console.aws.amazon.com/route53/
  • In the navigation pane, choose Hosted Zones
  • Choose the name of the hosted zone for the domain name that you want to use to route traffic to your EC2 instance
  • Choose Create Record Set
  • Specify the value as mentioned in P.S.2 below.
  • Choose Create

Changes usually propagate to all Amazon Route 53 servers within 60 seconds. When propagation is done, you’’ll be able to route traffic to your EC2 instance using the name of the resource record set that you created in this procedure.

Configuring EC2 instance to receive HTTP requests

After you have done all the steps above, traffic will be routed to your EC2 instance, however, you need to allow your EC2 instance to receive the http requests as well. You will need to follow the steps below:

  • Open EC2 console on https://console.aws.amazon.com/ec2/
  • On the left pane, choose Security Groups
  • From the table, select the security group your EC2 instance belongs to. This will make the settings of that group visible in the bottom of the console.
  • Select Inbound tab and choose the Edit button.
  • Click on the Add Rule button and enter following values then click Save
  • Once you have done these steps, your EC2 instance will be able to receive HTTP requests on port 80.

    P.S.1 How to get IP address of an EC2 instance

    • Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
    • Note: make sure you have selected your desired region from upper right corner of the console

    • In the navigation pane, choose Instances
    • In the table, choose the instance that you want to route traffic to
    • In the bottom pane, on the Description tab, get the value of Elastic IPs
    • If you did not associate an Elastic IP with the instance, get the value of Public IP

    P.S.2 Values for the record set

    Name: Type the domain name that you want to use to route traffic to your EC2 instance, e.g. www.example.com. The default value is the name of the hosted zone. For example, if the name of the hosted zone is example.com and you want to use www.example.com to route traffic to your EC2 instance, type www.

    Type: Choose A-IPv4 Address

    Alias: Choose No

    TTL (Seconds): Accept the default value (300) or change as you wish

    Value: Type the IP address (Public IP or Elastic IP) that you got in P.S.1 above

    Routing Policy: Accept the default value simple

Share post:
XpertFinder

Need more information? Follow us on:

Subscribe to newsletter

*Stay up to date with upcoming sessions and blog posts.

©2019-2020 All rights reserved. Made by Atar Dev
Top