问题
I tried to find/get s3 bucket information using javascript/nodejs aws-sdk, but I didnt find such apis. How to get s3 bucket size / information via aws-sdk (javascript or node) api.
回答1:
There is no API to get the bucket size other than enumerating all the objects.
One alternative approach would be to investigate the billing, but I think that will only yield inaccurate data as the billing handles a specific size over a specific time.
回答2:
Once a day the size of the bucket is reported to CloudWatch. The Metric is called BucketSizeBytes and you can supply the BucketName as a dimension and the StorageType (AllStorageTypes, StandardStorage, StandardIAStorage, ReducedRedundancyStorage).
You can use the JavaScript SDK to acceess the data in CloudWatch via the getMetricStatistics of the CloudWatch client. http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#getMetricStatistics-property
来源:https://stackoverflow.com/questions/40042150/how-to-get-s3-bucket-size-via-aws-sdk-javascript-or-node