I wrote a java program, where I am uploading a 1GB text file into S3 bucket(uploading using Lambda from one S3 bucket to another). But I am getting "java.lang.OutOfMemoryError: Java heap space" . I have changed the heap memory to 2048 mb but still it's not working .
Here's the code :
public void s3Upload() throws UnsupportedEncodingException {
try{
final AmazonS3 s3Client =AmazonS3ClientBuilder.standard().
withRegion(Regions.US_EAST_1).build();
System.out.println(" Creating file transfer ");
final S3Object s3Object = s3Client.getObject("my01bucket", "S3text.txt");
final S3ObjectInputStream s3ObjectInputStream = s3Object.getObjectContent();
final long contentLength = s3ObjectInputStream.toString().length();
final ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType("text/plain ; charset=utf-8");
objectMetadata.setContentLength(contentLength);
System.out.println("Uploading file....");
final TransferManager tm = TransferManagerBuilder.standard().withS3Client(s3Client).
withMultipartUploadThreshold((long)5*1024*1024).build();
final Transfer upload = tm.upload(String.valueOf(System.getenv("S3_BUCKET_URL")),
"S3text1.txt", s3ObjectInputStream , new ObjectMetadata());
upload.waitForCompletion();
tm.shutdownNow();
} catch (InterruptedException | AmazonClientException e) {
e.printStackTrace();
}
}
Note: used Lambda cause that's where the business logic will take place. Uploading from one bucket to another , just to check the file uploading functionality into S3 using java.