If you need to get the size of an AWS S3 folder, or even an entire bucket, you can do so with the following command:

aws s3api --profile  list-objects --bucket --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'

If you don’t use aws cli profiles, then you can leave out the profile part like this:

aws s3api list-objects --bucket --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'

Remember to replace <bucket_name> with your own bucket name.