AWS S3 CLI: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==AWS CLI S3 Commands== Using the AWS CLI to query S3 for bucket or folder statistics. ===List buckets in account with s3api=== <syntaxhighlight lang="bash"> aws s3api list-...") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
===List bucket size with s3api=== | ===List bucket size with s3api=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
aws s3api list-objects --bucket | aws s3api list-objects --bucket <bucket_name> --output json --query "[sum(Contents[].Size), length(Contents[])]" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===List objects in bucket with totals=== | ===List objects in bucket with totals=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
aws s3 ls --summarize --human-readable --recursive s3:// | aws s3 ls --summarize --human-readable --recursive s3://<bucket_name>/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===List summary of specific folder within a bucket=== | ===List summary of specific folder within a bucket=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
aws s3 ls --summarize --human-readable --recursive s3:// | aws s3 ls --summarize --human-readable --recursive s3://<bucket_name>/<folder_name> | Select-String -Pattern Total | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===List bucket size by polling CloudWatch metrics=== | ===List bucket size by polling CloudWatch metrics=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
aws cloudwatch get-metric-statistics --namespace AWS/S3 --dimensions Name=BucketName,Value= | aws cloudwatch get-metric-statistics --namespace AWS/S3 --dimensions Name=BucketName,Value=<bucket_name> Name=StorageType,Value=StandardStorage --metric-name BucketSizeBytes --start-time 2019-10-30T00:00:00 --end-time 2019-10-31T00:00:00 --period 86400 --statistics Average --unit Bytes | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===List multipart uploads=== | ===List multipart uploads=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
aws s3api list-multipart-uploads --bucket | aws s3api list-multipart-uploads --bucket <bucket_name> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Summarize Folder Total=== | ===Summarize Folder Total=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> |
Latest revision as of 18:59, 26 March 2020
AWS CLI S3 Commands
Using the AWS CLI to query S3 for bucket or folder statistics.
List buckets in account with s3api
aws s3api list-buckets --query "Buckets[].Name"
List bucket size with s3api
aws s3api list-objects --bucket <bucket_name> --output json --query "[sum(Contents[].Size), length(Contents[])]"
List objects in bucket with totals
aws s3 ls --summarize --human-readable --recursive s3://<bucket_name>/
List summary of specific folder within a bucket
aws s3 ls --summarize --human-readable --recursive s3://<bucket_name>/<folder_name> | Select-String -Pattern Total
List bucket size by polling CloudWatch metrics
aws cloudwatch get-metric-statistics --namespace AWS/S3 --dimensions Name=BucketName,Value=<bucket_name> Name=StorageType,Value=StandardStorage --metric-name BucketSizeBytes --start-time 2019-10-30T00:00:00 --end-time 2019-10-31T00:00:00 --period 86400 --statistics Average --unit Bytes
List multipart uploads
aws s3api list-multipart-uploads --bucket <bucket_name>
Summarize Folder Total
aws s3 ls --summarize --human-readable --recursive s3://<bucket_name>/<folder_name> | Select-String -Pattern Total