@Override
    public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) {
        if (SDKGlobalConfiguration.isEc2MetadataDisabled()) {
            throw new AmazonClientException("EC2 Instance Metadata Service is disabled");
        }

        Map<String, String> newHeaders = addDefaultHeaders(headers);
        String token = getToken();

        if (token != null) {
            newHeaders.put(TOKEN_HEADER, token);
        } else if (SDKGlobalConfiguration.isEc2MetadataV1Disabled() || isEc2MetadataV1DisabledInProfileFile()) {
            String errorMsg = String.format("Failed to retrieve IMDS token, and fallback to IMDS v1 is disabled via " +
                            "the %s environment variable and/or %s system property and/or %s profile property.",
                    AWS_EC2_METADATA_V1_DISABLED_ENV_VAR,
                    AWS_EC2_METADATA_V1_DISABLED_SYSTEM_PROPERTY,
                    AWS_EC2_METADATA_V1_DISABLED_PROFILE_PROPERTY);
            throw new AmazonClientException(errorMsg);
        }

        return doReadResource(endpoint, retryPolicy, newHeaders);
    }
Connects to the given endpoint to read the resource
and returns the text contents.
aws-java-sdk-core/src/main/java/com/amazonaws/internal/InstanceMetadataServiceResourceFetcher.java