Amazon S3 and Cloudfront with Java API


I am currently using S3 with the Java API to get objects and their content. I've created a Cloudfront distribution using the AWS console and I set my S3 bucket with my objects as the Bucket-origin. But I didn't notice any improvement in the download performance, and I noticed in the console window the url refers to s3:

INFO: Sending Request: GET /picture.jpg Headers: (Range: bytes=5001-1049479, Content-Type: application/x-www-form-urlencoded; charset=utf-8, )

whereas in the Getting Started guide for Cloudfront, the url should be:

http://(domain name)/picture.jpg

where (domain name) is specific to the Cloudfront distribution. So the Java API still is getting the file from S3 and not through cloudfront

Is there anyway using the Java API for S3 to download files via Cloudfront? If not, what's the best approach I should use to get objects via cloudfront in my java program? I am still kinda new to this stuff, any help greatly appreciated!

URL url = new URL(your_cloudfront_url);
InputStream in = url.openStream();

But, you should know that it can take 24 hours or more for changes in S3 to be active. If you cannot open the stream, the other way is to use getObject(bucketName, key) method.

JAVA API for S3 can not be used for interacting with Cloudfront.

If you want to download the content through cloud front distribution, you have to write your own HTTP code (which should be simple). You can also just use http://(cloud front domain name)/picture.jpg in browser and check the download speed first.

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