如何找到我的 AWS S3 存储桶或文件夹的总大小? [英] How do I find the total size of my AWS S3 storage bucket or folder?
本文介绍了如何找到我的 AWS S3 存储桶或文件夹的总大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亚马逊是否提供了一种简单的方法来查看我的 S3 存储桶或文件夹使用了多少存储空间?这样我就可以计算我的成本等.
Does Amazon provide an easy way to see how much storage my S3 bucket or folder is using? This is so I can calculate my costs, etc.
推荐答案
两种方式,
aws s3 ls --summarize --human-readable --recursive s3://bucket/folder/*
如果我们最后省略/
,它会得到所有以你的文件夹名称开头的文件夹,并给出所有的总大小.
If we omit /
in the end, it will get all the folders starting with your folder name and give a total size of all.
aws s3 ls --summarize --human-readable --recursive s3://bucket/folder
使用 boto3 api
import boto3
def get_folder_size(bucket, prefix):
total_size = 0
for obj in boto3.resource('s3').Bucket(bucket).objects.filter(Prefix=prefix):
total_size += obj.size
return total_size
这篇关于如何找到我的 AWS S3 存储桶或文件夹的总大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文