code: public static boolean isInEc2(InstanceInfo instanceInfo) {
          if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
              String instanceId = ((AmazonInfo) instanceInfo.getDataCenterInfo()).getId();
              if (instanceId != null && instanceId.startsWith("i-")) {
                  return true;
              }
          }
          return false;
      }
docs: check to see if the instanceInfo record is of a server that is deployed within EC2 (best effort check based
  on assumptions of underlying id). This check could be for the local server or a remote server.
  
  @param instanceInfo
  @return true if the record contains an EC2 style "i-*" id