gpt4 book ai didi

amazon-web-services - 如何找到我的 AWS S3 存储桶或文件夹的总大小?

转载 作者:行者123 更新时间:2023-12-03 10:46:20 26 4
gpt4 key购买 nike

Amazon 是否提供了一种简单的方法来查看我的 S3 存储桶或文件夹使用了多少存储?这样我就可以计算我的成本等。

最佳答案

两种方式,

使用 aws cli

aws s3 ls --summarize --human-readable --recursive s3://bucket/folder/*

如果我们省略 /最后,它将获取以您的文件夹名称开头的所有文件夹,并给出所有文件夹的总大小。

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

关于amazon-web-services - 如何找到我的 AWS S3 存储桶或文件夹的总大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32192391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com