import socket


def is_ec2_instance(hostname=None):
    """Checks if *hostname* refers to an ec2 instance.  If hostname is not
    given, assumes the check is for the local machine.
    """
    if hostname is None:
        hostname = socket.getfqdn()
    domain = (hostname.split('.'))[-1]
    return domain == 'internal'