somspeaks
somspeaks

Reputation: 604

SdkClientException: Unable to execute HTTP request: Connection reset

I'm trying to upload file to AWS s3 bucket. I'm continuously getting this exception "SdkClientException: Unable to execute HTTP request: Connection reset".

I'm trying to upload by inputstream

AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(Regions.US_EAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(cred))
                .build();
        try {

            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentLength(bytesArray.length);
            metadata.setContentType("text/csv");
            s3Client.putObject(new PutObjectRequest(appConfig.getBucketName(), fileName, inStream, metadata).withCannedAcl(CannedAccessControlList.PublicRead));
        }
    ----

Below is the exception in detail. What could be the reason? My S3 bucket has IAM user with S3 full access policy. Is this issue related to network or any other settings?

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connection reset
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1136)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1082)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:745)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)
-------
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
    at com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.connectSocket(SdkTLSSocketFactory.java:142)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142

Upvotes: 15

Views: 60283

Answers (3)

cheparsky
cheparsky

Reputation: 530

In my case, disabling the AWS Toolkit plugin works.

Upvotes: 0

jfk
jfk

Reputation: 5317

If you are running the application behind a proxy, this may happens. You can set the proxy as,

public static void setProxy() {
        System.setProperty("http.proxyHost", "<http-proxy-url>");
        System.setProperty("http.proxyPort", "<port>");

        System.setProperty("https.proxyHost", "<https-proxy-url>");
        System.setProperty("https.proxyPort", "<port>");
    }

Upvotes: 0

somspeaks
somspeaks

Reputation: 604

I found it is occurring due to the firewall. If you set logging.level.com.amazonaws at DEBUG then it will show SSL handshake failing.

Upvotes: 3

Related Questions