I am trying to use this example from the AWS documentation to get a file from S3.
The file I am trying to read from S3 is a binary file. I need the InputStream from s3object.getObjectContent() to work with it in another framework. If I am trying to save the S3ObjectInputStream I receive the following error:
WARNING: Not all bytes were read from the S3ObjectInputStream, aborting HTTP connection. This is likely an error and may result in sub-optimal behavior. Request only the bytes you need via a ranged GET or drain the input stream after use.
My code is actually pretty easy:
public String handleRequest(S3Event event, Context context) {
context.getLogger().log("Received event: " + event.toJson());
// Get the object from the evØent and show its content type
String bucket = event.getRecords().get(0).getS3().getBucket().getName();
String key = event.getRecords().get(0).getS3().getObject().getKey();
try (S3Object response = s3.getObject(new GetObjectRequest(bucket, key))) {
Long filesize = response.getObjectMetadata().getContentLength();
System.out.println("File size is: " + filesize);
S3ObjectInputStream s3is = response.getObjectContent();
MsgParser msgp = new MsgParser();
Message msg = msgp.parseMsg(s3is);
String fromEmail = msg.getFromEmail();
String fromName = msg.getFromName();
String subject = msg.getSubject();
} catch (Exception e) {
System.out.println("Unable to get file from S3 with reason: " + e);
}
return "";
}
What is my error here?