Downloading an image from AWS S3 using java AWS S3 client sdk and cloudfront CDN end point

Question!

Currently, I am using the AmazonS3Client instance to download the S3 object using the "key" and "bucket name" as given below.

object = s3Client.getObject(new GetObjectRequest(BucketDetails.getBucketDetails(), iconPath));
file  = new File(destinationPath);
reader = new BufferedInputStream( object.getObjectContent());        
writer = new BufferedOutputStream(new FileOutputStream(file));  
int read = -1;  
while ( ( read = reader.read() ) != -1 ) 
{     
      writer.write(read); 
}  
writer.flush(); 
writer.close();
reader.close(); 

This by default points to default S3 end point.

I have created a cloudfront distribution for my S3 access.

Can I set the endpoint of AmazonS3Client to cloud front distribution to improve the download performance?



Answers

If you have Cloudfront distribution, and have made the files public, you shouldn't need any sort of AWS client library to access it. You can just grab the file using your file retrieval mechanism of choice.



This video can help you solving your question :)
By: admin