Getting an exception com.amazonaws.http.timers.client.SdkInterruptedException
on executing below line of code.
S3Object response = s3client.getObject(new GetObjectRequest(s3URI.getBucket(), s3URI.getKey()));
The sdk version, code and stack trace are mentioned below. What could be the issue and how to resolve this?
Version Info
- Java version: 1.8
- AWS SDK Version: 1.11.1026
Dependency
- com.amazonaws:aws-java-sdk-bundle:jar:1.11.1026
Code
public static ByteArrayOutputStream getS3Object(String path) {
AmazonS3 s3client = null;
try {
AmazonS3URI s3URI = new AmazonS3URI(path);
s3client = AmazonS3ClientBuilder.defaultClient();
S3Object response = s3client.getObject(new GetObjectRequest(s3URI.getBucket(), s3URI.getKey()));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = response.getObjectContent().read(buffer)) != -1) {
byteArrayOutputStream.write(buffer, 0, bytesRead);
}
response.close();
return byteArrayOutputStream;
} catch (AbortedException | IOException e) {
e.printStackTrace();
System.err.println("AWS call interrupted retrying " + e);
} finally {
if (s3client != null) {
s3client.shutdown();
}
}
throw new RuntimeException("s3 object is null");
}
Stack trace
com.amazonaws.AbortedException:
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleInterruptedException(AmazonHttpClient.java:880)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:757)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:715)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:697)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:561)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:541)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5456)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5403)
at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1524)
com.example.S3Utils.getS3Object(S3Utils.java:78)
Caused by: com.amazonaws.http.timers.client.SdkInterruptedException
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.checkInterrupted(AmazonHttpClient.java:935)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.checkInterrupted(AmazonHttpClient.java:921)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1115)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:814)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:781)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:755)
... 53 more
2
Answers
You are using an SDK version that is on path to deprecation as mentioned in my comment. Now to get an S3 object using AWS SDK for Java V2, you can use this code. If you do not know how to get up and running with V2, see DEV Guide:
Developer Guide – AWS SDK for Java 2.x
You can find the POM in the AWS Code Example Github here:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/s3
@smac2020, Amazon SDK interrupt exception. Is this handled using AWS retry policy or
Thread.currentThread().sleep(sleep_time)
Also, how to load cred when it’s used iam role based access to s3?