in src/main/java/software/amazon/cloudwatchlogs/emf/environment/EC2Environment.java [53:95]
public boolean probe() {
String token;
Pair<String, String> tokenRequestHeader =
new Pair<>(TOKEN_REQUEST_HEADER_KEY, TOKEN_REQUEST_HEADER_VALUE);
URI tokenEndpoint = null;
try {
tokenEndpoint = new URI(INSTANCE_TOKEN_URL);
} catch (Exception ex) {
log.debug("Failed to construct url: " + INSTANCE_IDENTITY_URL);
return false;
}
try {
token =
fetcher.fetch(
tokenEndpoint, "PUT", Collections.singletonList(tokenRequestHeader));
} catch (EMFClientException ex) {
log.debug("Failed to get response from: " + tokenEndpoint, ex);
return false;
}
Pair<String, String> metadataRequestTokenHeader =
new Pair<>(METADATA_REQUEST_TOKEN_HEADER_KEY, token);
URI endpoint = null;
try {
endpoint = new URI(INSTANCE_IDENTITY_URL);
} catch (Exception ex) {
log.debug("Failed to construct url: " + INSTANCE_IDENTITY_URL);
return false;
}
try {
metadata =
fetcher.fetch(
endpoint,
"GET",
EC2Metadata.class,
Collections.singletonList(metadataRequestTokenHeader));
return true;
} catch (EMFClientException ex) {
log.debug("Failed to get response from: " + endpoint, ex);
}
return false;
}