public String readResource ( String resourcePath ) throws IOException , SdkClientException { URL url = getEc2MetadataServiceUrlForResource ( resourcePath ) ; log . debug ( "Connecting to EC2 instance metadata service at URL: " + url . toString ( ) ) ; HttpURLConnection connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . setConnectTimeout ( 1000 * 2 ) ; connection . setReadTimeout ( 1000 * 5 ) ; connection . setRequestMethod ( "GET" ) ; connection . setDoOutput ( true ) ; connection . addRequestProperty ( "User-Agent" , USER_AGENT ) ; connection . connect ( ) ; return readResponse ( connection ) ; }
Connects to the metadata service to read the specified resource and returns the text contents .