Amazon EC2 Public DNS is useless?

433

Solution 1

The public DNS name (whether elastic IP address or not) is exactly the same as using the public IP address (elastic IP or not) with the one following important difference:

If you query the public DNS name from outside of EC2, it resolves to the public IP address. If you query the public DNS name from inside of EC2, it resolves to the private IP address.

You can use this trick with or without Elastic IP addresses. I recommend using Elastic IP addresses as it keeps the public DNS name the same even after stop/start or moving your service to another EC2 instance. Because of this, you can always use the public DNS name of the Elastic IP address and it will resolve to the internal IP address of the current instance to which the Elastic IP is associated.

You can extend this by using a CNAME DNS entry where you map your preferred hostname to the external DNS name of the Elastic IP.

Here's an article I wrote about using this feature to save money and speed up network performance with internal EC2 communication without having to keep track of the current internal IP address for each instance on all your other instances: http://alestic.com/2009/06/ec2-elastic-ip-internal

Other than this one difference, I agree that you might as well use the public IP address instead of the public DNS name because:

  1. You save time by not doing a DNS lookup

  2. You avoid any security risks that occasionally arise in the DNS protocol.

so I suppose, in reality, right there are two more differences...

Solution 2

You'd use the EC2 public address to do things like SSHing into that server, or for interconnecting EC2 instances, or any number of other things.

If you need a consistent address (say to point users at), you'd provision an Elastic Load Balancer or an Elastic IP to sit in front of your instance(s).

Also, within EC2, public DNS resolves to the instance's internal IP, but outside EC2 it resolves to the external IP. This can be useful at times, as communicating between EC2 nodes using the private IP saves you money.

Solution 3

Well they only change when you stop the instance. If your instance is going to be long lived you can just point a CNAME to it and it will work. They're not completely useless, they are just transient.

Solution 4

You can use Elastic IP's

Here is an article on them

http://aws.amazon.com/articles/1346

Share:
433
yellowB
Author by

yellowB

Updated on September 18, 2022

Comments

  • yellowB
    yellowB over 1 year

    Background

    I am working on a MEAN stack project, which needs to store some data in browser's localStorage.

    Since there is limitation on the capacity of localStorage(several megaBytes) and the data volumn is not predictable, I have to handle this problem.

    Similar to this answer: make localStorage or sessionStorage expire like cookies [duplicate], I made some common functions for getting/setting items in localStorage. Every item contains an _expires field to indicate when the item will be expired. This filed will be checked when the getLocalStorageItem function is called, if expired, the item will be removed.

    angular.module('ca.interaction').factory('CommonService', function() {
        return {
            // Check expired time before getting item from localStorage
            getLocalStorageItem: function (name) {
                var v = localStorage.getItem(name);
                try {
                    if (v) {
                        var v2 =  JSON.parse(v);
                        var now = new Date().getTime();
                        if (v2._expires && v2._expires >= now) {
                            return v2._val;
                        } else if (v2._expires && v2._expires < now) {
                            localStorage.removeItem(name);
                            return "";
                        } else {
                            return v;
                        }
    
                    } else {
                        return "";
                    }
                } catch (e) {
                    return v;
                }
            },
            // Set expire time when storing an item
            saveLocalStorageItem: function (name, value, expires) {
                var expiresDateTime = new Date().getTime() + expires;
                localStorage.setItem( name, JSON.stringify({_val: value, _expires: expiresDateTime}) );
            },
            removeLocalStorageItem: function (name) {
                localStorage.removeItem(name);
            }
        }
    });
    

    Problem

    If the program stores items into localStorage in a high frequency and all of them are not expired yet, the capacity limitation will be exceed.

    So my original idea is to implement a FIFO(First In First Out) mechanism: use a sorted queue data Structure to hold all the keys and their Creation time(keys are sorted by Creation time from oldest to youngest). When the localStorage is full and the program continue to store a new item, the oldest key will be kicked out of the queue and the item corresponding to the key will be removed from localStorage.

    But I meet some technical difficulties:

    1. How can I get all existing keys from localStorage? Because I may need to re-construct the queue when user refreshes browser and the program reloads. I read Storage API in MDN but no API can do this.
    2. How can I know how much free space remaining in localStorage? Because before storing a new item, I need to do a calculation and know how many oldest items should be removed.

    I am not sure if any existing library/framework can achieve this goal, please share your advice

    • Admin
      Admin almost 12 years
      In certain cases, where you can setup only CNAME records., the public DNS comes into play.
    • Admin
      Admin almost 12 years
      @CS3, you can do it by using A record to the instance. Since both the public IP and DNS have the same lifespan.
    • Admin
      Admin almost 12 years
      'A' Records can be mapped to IP addresses. But if the same machine exposes different services with the same address, CNAMEs can help convey meaningful domain names. ( Eg: ftp.domain.tld, www.domain.tld ).
    • Admin
      Admin almost 12 years
      There is only one difference between the public DNS and public IP. See my answer below.
    • Admin
      Admin over 5 years
      I have exactly the same question 3 years on . My conclusion... the public DNS is pretty useless. If they had assigned a unique but permanently fixed public DNS (e.g. a guid), I would be able to stop/start my instance, knowing that my SSH and SFTP connections I have already setup will still work. It seems this simple thing is impossible without buying an elastic IP address.. which is a huge waste for an instance which is only started occasionally.
  • Shyam Sundar C S
    Shyam Sundar C S almost 12 years
    Doesnt answer the question asked. Whatever you said, could be done using IP addresses also.
  • ceejayoz
    ceejayoz almost 12 years
    @Yoga If you don't need it, don't use it. What, exactly, are you going for here?
  • Eric Hammond
    Eric Hammond almost 12 years
    ceejayoz did answer the question in the third paragraph (DNS resolution inside and outside of EC2). I've expanded on this in my answer which only focuses on this difference.
  • ceejayoz
    ceejayoz almost 12 years
    @EricHammond In fairness, I was editing that in when Yoga posted.