AWS使用Java API获取S3存储桶大小 [英] Aws get S3 Bucket Size using java api

查看:539
本文介绍了AWS使用Java API获取S3存储桶大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google上搜索了有关获取有关S3存储桶的元数据的有效方法,例如其大小和文件数.我发现链接讨论了这样的问题问题.但这适用于PHP和使用Cloud-Watch的AWS CLI.我想知道是否有一些Java API可以提取s3存储桶元数据?

I have searched on google about efficient way to get metadata about S3 bucket like its size and number of files in it. I found this link discussing such problem. But it's for PHP and aws cli using cloud-watch. I want to know is there some java api to fetch the s3 bucket metadata?

谢谢

推荐答案

您可以在此处找到AWS S3 Java库的广泛文档:

You can find the extensive documentation of the AWS S3 Java library here:

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/overview-summary.html

回答您的问题,您可以使用getSize()来获取S3中对象的大小,并且可以遍历所有文件来获取存储桶的大小.

Answering your question, you can use getSize() for getting the size of an object in S3 and you can iterate over all of your files to get the size of your bucket.

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3ObjectSummary.html#getSize()

S3不支持直接收集磁盘使用情况(这意味着不遍历所有项目),但是您可以使用CloudWatch来获取要用于单个请求的数据.

S3 does not support gathering disk usage directly (meaning not iterating through all of the items) but you can use CloudWatch to get the data you would like to use with a single request.

查询示例:

aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time 2016-01-01T10:00:00 --end-time 2016-02-12T01:00:00 --period 86400 --statistics Average --region us-east-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=www.streambrightdata.com Name=StorageType,Value=StandardStorage

返回:

{
    "Datapoints": [
        {
            "Timestamp": "2016-02-05T10:00:00Z",
            "Average": 54027423.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-03T10:00:00Z",
            "Average": 52917504.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-04T10:00:00Z",
            "Average": 53417421.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-07T10:00:00Z",
            "Average": 54949563.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-01T10:00:00Z",
            "Average": 24951965.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-02T10:00:00Z",
            "Average": 28254636.0,
            "Unit": "Bytes"
        },
        {
            "Timestamp": "2016-02-06T10:00:00Z",
            "Average": 54577328.0,
            "Unit": "Bytes"
        }
    ],
    "Label": "BucketSizeBytes"
}

用于CloudWatch的AWS Java SDK:

AWS Java SDK for CloudWatch:

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudwatch/AmazonCloudWatchClient.html

这篇关于AWS使用Java API获取S3存储桶大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆