private static Map < String , String > initializeAwsIdentityDocument ( ) { InputStream stream = null ; try { stream = openStream ( AWS_INSTANCE_IDENTITY_DOCUMENT_URI ) ; String awsIdentityDocument = slurp ( new InputStreamReader ( stream , Charset . forName ( "UTF-8" ) ) ) ; return parseAwsIdentityDocument ( awsIdentityDocument ) ; } catch ( IOException e ) { // Cannot connect to http://169.254.169.254/latest/dynamic/instance-identity/document. // Not on an AWS EC2 instance. } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( IOException e ) { // Do nothing. } } } return Collections . emptyMap ( ) ; }
This method should only be called once .