code: private String getLocalInstanceId(final String cloudProvider, final String metadataEndpoint, final Map<String,String> headers) {
  		String detectedInstanceId = null;
  		try {
  			final URL metadataUrl = new URL(metadataEndpoint);
  			URLConnection metadataConnection = metadataUrl.openConnection();
  			// add any additional headers passed in
  			if (headers != null) {
  				for (Map.Entry<String, String> header : headers.entrySet()) {
  					metadataConnection.setRequestProperty(header.getKey(), header.getValue());
  				}
  			}
  			BufferedReader in = new BufferedReader(new InputStreamReader(metadataConnection.getInputStream(), "UTF-8"));
  			String inputLine;
  			while ((inputLine = in.readLine()) != null) {
  				detectedInstanceId = inputLine;
  			}
  			in.close();
  		} catch (Exception e) {
  			logger.warn("unable to determine " + cloudProvider + " instance ID", e);
  		}
  		return detectedInstanceId;
  	}
docs: Use a Cloud provider local metadata endpoint to determine the instance ID that this code is running on.
  Useful if you don't want to configure the instance ID manually.
  Pass detectInstance param with a cloud provider ID (AWS|GCE) to have this run in your configuration.
  
  @return String containing an instance id, or null if none is found