AWS S3 CLI: Difference between revisions

From SWKLS WIKI
Jump to navigation Jump to search
 
(2 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 svcostaffbackup --output json --query "[sum(Contents[].Size), length(Contents[])]"
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">
Line 23: Line 24:
===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=svcostaffbackup 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
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 svcostaffbackup
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