private boolean autoDetectEc2(AmazonInfoConfig amazonInfoConfig) {
        try {
            URL url = AmazonInfo.MetaDataKey.instanceId.getURL(null, null);
            String id = AmazonInfoUtils.readEc2MetadataUrl(
                    AmazonInfo.MetaDataKey.instanceId,
                    url,
                    amazonInfoConfig.getConnectTimeout(),
                    amazonInfoConfig.getReadTimeout()
            );

            if (id != null) {
                logger.info("Auto detected EC2 deployment environment, instanceId = {}", id);
                return true;
            } else {
                logger.info("Auto detected non-EC2 deployment environment, instanceId from metadata url is null");
                return false;
            }
        } catch (SocketTimeoutException e) {
            logger.info("Auto detected non-EC2 deployment environment, connection to ec2 instance metadata url failed.");
        } catch (Exception e) {
            logger.warn("Failed to auto-detect whether we are in EC2 due to unexpected exception", e);
        }
        return false;
    }
private boolean autoDetectEc2 ( AmazonInfoConfig amazonInfoConfig ) { try { URL url = AmazonInfo . MetaDataKey . instanceId . getURL ( null , null ) ; String id = AmazonInfoUtils . readEc2MetadataUrl ( AmazonInfo . MetaDataKey . instanceId , url , amazonInfoConfig . getConnectTimeout ( ) , amazonInfoConfig . getReadTimeout ( ) ) ; if ( id != null ) { logger . info ( "Auto detected EC2 deployment environment, instanceId = {}" , id ) ; return true ; } else { logger . info ( "Auto detected non-EC2 deployment environment, instanceId from metadata url is null" ) ; return false ; } } catch ( SocketTimeoutException e ) { logger . info ( "Auto detected non-EC2 deployment environment, connection to ec2 instance metadata url failed." ) ; } catch ( Exception e ) { logger . warn ( "Failed to auto-detect whether we are in EC2 due to unexpected exception" , e ) ; } return false ; }
best effort try to determine if we are in ec2 by trying to read the instanceId from metadata url