我正在尝试将文件上传到AWS s3存储桶。我不断收到此异常“ SdkClientException:无法执行HTTP请求:连接重置”。
我正在尝试通过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));
}
----
下面是详细的例外情况。可能是什么原因?我的S3存储桶具有具有S3完全访问策略的IAM用户。此问题与网络或任何其他设置有关吗?
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
答案 0 :(得分:0)
我发现这是由于防火墙引起的。如果将DEBUG设置为logging.level.com.amazonaws,则它将显示SSL握手失败。
答案 1 :(得分:0)
如果您在代理后面运行应用程序,则可能会发生这种情况。您可以将代理设置为,
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>");
}