开发者

Amazon S3 and Cloudfront with Java API

开发者 https://www.devze.com 2023-03-17 05:22 出处:网络
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. B

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 https://mybucket.s3.amazonaws.com /picture.jpg Headers: (Range: bytes=5001-1049479, Content-Type: application/x-www-form-urlencoded; charset=utf-8, )

whereas in the Getting开发者_C百科 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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消